home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / whisper / source / wind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  57.5 KB  |  2,880 lines

  1. /*
  2.     Wind Consol
  3. */
  4. #include    <stdio.h>
  5. #include    <stdlib.h>
  6. #include    <string.h>
  7. #include    <ctype.h>
  8. #include    <mos.h>
  9. #include    "defs.h"
  10. #include    "event.h"
  11. #include    "graphic.h"
  12. #include    "msg.h"
  13. #include    "buff.h"
  14. #include    "coldef.h"
  15. #include    "wind.h"
  16.  
  17. #define    unlink(f) remove(f)
  18.  
  19. #define    FONT_SIZ    16
  20. #define    TAB        8
  21. #define    CUR_COL        8
  22.  
  23. /********
  24. #define    TERM        0
  25. *********/
  26.  
  27. #define    W_NAME_X    4
  28. #define    W_UP_X        50
  29. #define    W_DOWN_X    (W_UP_X+24)
  30. #define    W_UPLOAD_X    (W_DOWN_X+32)
  31. #define    W_MENU_X    (W_UPLOAD_X+64)
  32. #define    W_DIAL_X    (W_MENU_X+44)
  33. #define    W_DOWNLD_X    (W_DIAL_X+44)
  34. #define    W_CHILD_X    400
  35. #define    W_SECRET_X    520
  36. #define    W_MOVE_X    600
  37.  
  38. void    WIN_resize(void);
  39. void    WIN_open(int no);
  40. void    WIN_act_cheng(int no);
  41. char    *read_line(char tmp[],FILE *fp);
  42. char    *strdup(char *str);
  43. void    WIN_upload(int no);
  44. char    *secret_file();
  45. int    iskan(char *str);
  46. void    DSP_xline();
  47. int    secret_chk(char *file);
  48. void    RSB_putc(int ch);
  49. int    RSB_chk(void);
  50. int    RSB_getc(void);
  51. void    cputstr();
  52. int    kbhit();
  53. int    getkey(unsigned *ec);
  54. int    macval(char *mac);
  55. void    macvalset(char *mac,int val);
  56. void    macset(char *mac,char *str);
  57. void    KAN_touroku(int len,char *tango);
  58. void    MEMO_insrt(int no,int ch);
  59. int    EDIT_KEY_chk(int code);
  60. int    EDIT_KEY_exec(int code,int no);
  61. int    TERM_KEY_exec(int code);
  62. int    LIN_buf_pos(void);
  63. void    LIN_buf_dsp(void);
  64. void    LIN_buf_flush(void);
  65. void    LIN_input(int ch);
  66. void    eof_chk(FILE *fp);
  67. void    KEY_line_top(void);
  68.  
  69. extern int    key_flg;
  70.  
  71.        int    TERM=0;
  72.        int    lin_new_flg=FALSE;
  73.        int    act_wind=0;
  74.        WIND    win[MAX_WIND];
  75. static int    bak_ins_mode=TRUE;
  76. static int    cur_dsp_flg=FALSE;
  77. static int    cur_dsp_ptn=0;
  78. static int    cur_dsp_col=15;
  79. static int    cur_wind=ERR;
  80. static int    wind_count=0;
  81. static int    up_memo=ERR;
  82. static int    up_wind=ERR;
  83. static int    up_child=ERR;
  84. static FILE    *down_fp=NULL;
  85. static int    log_max=1000;
  86. static int    scl_flg=FALSE;
  87. static int    lin_flg=FALSE;
  88. static char     *memo_buf=NULL;
  89. static int    memo_ptr=ERR;
  90. static char    undo[120];
  91.  
  92. static char    *win_name[]={ "MIKE","JOHN","KENT" };
  93. static char *child_name[]={
  94.     "\x1B\xE8","\x1B\xE9","\x1B\xEA","\x1B\xEB","\x1B\xEC" };
  95. static int      wind_col[MAX_WIND]={ COL_MIKE,COL_JOHN,COL_KENT };
  96. static int      wind_col2[MAX_WIND]={ COL_MIKE2,COL_JOHN2,COL_KENT2 };
  97. static struct {
  98.     struct {
  99.     short    top,siz;
  100.     } w[MAX_WIND];
  101. } win_tbl[MAX_WIND+1];
  102.  
  103. int    kan_pos(char *p,int n)
  104. {
  105.     int     i;
  106.  
  107.     for ( i = n ; i > 0 ; ) {
  108.     if ( *p == '\0' ) {
  109.         return (n - i);
  110.  
  111.     } else if ( iskan(p) ) {
  112.         i -= 2;
  113.         p += 2;
  114.  
  115.     } else {
  116.         i--;
  117.         p++;
  118.     }
  119.     }
  120.     return (n + i);
  121. }
  122. void    WIN_cursol(int no,int x,int y)
  123. {
  124.     int     sz;
  125.     static int bak_x=0,bak_y=0,bak_sz=0;
  126.     static char cur_ptn[][16]={
  127.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  128.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  129.     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  130.     0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,
  131.         0x00,0x08,0x08,0x1c,0x3e,0x7f,0x7f,0x7f,
  132.         0x7f,0x2a,0x08,0x1c,0x3e,0x00,0x00,0x00,
  133.         0x00,0x22,0x22,0x77,0x7f,0x7f,0x7f,0x7f,
  134.         0x3e,0x3e,0x1c,0x1c,0x08,0x00,0x00,0x00,
  135.         0x00,0x08,0x1c,0x1c,0x3e,0x3e,0x7f,0x7f,
  136.         0x3e,0x3e,0x1c,0x1c,0x08,0x00,0x00,0x00,
  137.         0x00,0x08,0x1c,0x1c,0x1c,0x08,0x6b,0x7f,
  138.         0x7f,0x6b,0x08,0x1c,0x3e,0x00,0x00,0x00,
  139.         0x00,0x00,0x18,0x3c,0x3c,0x7e,0x7e,0x7e,
  140.         0x7e,0x7e,0x3c,0x3c,0x18,0x00,0x00,0x00,
  141.         0x00,0x00,0x18,0x24,0x24,0x42,0x42,0x42,
  142.         0x42,0x42,0x24,0x24,0x18,0x00,0x00,0x00 };
  143.  
  144.     sz = cur_dsp_ptn + (win[no].ins_mode == FALSE ? 0:1);
  145.     if ( cur_wind != ERR ) {
  146.     if ( x == bak_x && y == bak_y && sz == bak_sz )
  147.         return;
  148.         MOS_disp(FALSE);
  149.     DSP_putptn(cur_ptn[bak_sz],bak_x,bak_y,cur_dsp_col,4);
  150.     MOS_disp(TRUE);
  151.     }
  152.  
  153.     if ( cur_dsp_flg == FALSE ) {
  154.     bak_sz = sz;
  155.     bak_x = x;
  156.     bak_y = y;
  157.         MOS_disp(FALSE);
  158.     DSP_putptn(cur_ptn[bak_sz],bak_x,bak_y,cur_dsp_col,4);
  159.     cur_wind = no;
  160.     MOS_disp(TRUE);
  161.     }
  162. }
  163. void    WIN_dsp_pause(int no,int sw)
  164. {
  165.     DSP_string( no == TERM ? "PAUSE":"UPLOAD",
  166.         W_UPLOAD_X+2,win[no].wind_y+4,
  167.         sw == FALSE ? wind_col2[no]:COL_RED,win[no].color);
  168. }
  169. void    WIN_dsp_down(int sw)
  170. {
  171.     DSP_string( "DOWN",W_DOWNLD_X+2,win[TERM].wind_y+4,
  172.         sw == FALSE ? wind_col2[TERM]:COL_RED,win[TERM].color);
  173. }
  174. void    WIN_dsp_secret(int no,int sw)
  175. {
  176.     DSP_string("SECRET",
  177.         W_SECRET_X+2,win[no].wind_y+4,
  178.         sw == FALSE ? wind_col2[no]:COL_RED,win[no].color);
  179. }
  180. void    WIN_dsp_buf(int no)
  181. {
  182.     int     i,n,y,fg=FALSE;
  183.     WIND    *wp;
  184.     register CHI_PTR *cp;
  185.     register LIN_PTR *lp;
  186.     char    *p,bch;
  187.     char    tmp[92];
  188.  
  189.     wp = &(win[no]);
  190.     cp = &(wp->child[wp->now]);
  191.     wp->wrt_mode = 0;
  192.  
  193.     if ( cp->cur_y >= wp->max_y )
  194.     cp->cur_y = wp->max_y - 1;
  195.  
  196.     if ( (n = cp->now_ptr) != ERR ) {
  197.     lp = get_lin(n);
  198.     if ( lp->left == ERR )
  199.         cp->cur_y = wp->max_y - 1;
  200.     }
  201.  
  202.     for ( i = cp->cur_y ; i > 0 && n != ERR ; i-- ) {
  203.     lp = get_lin(n);
  204.     if ( lp->right == ERR )
  205.         break;
  206.     n = lp->right;
  207.     }
  208.  
  209.     p = strcpy(tmp,"[EOF]");
  210.     y = wp->wind_y + 16;
  211.     for ( i = 0 ; i < wp->max_y ; i++ ) {
  212.     if ( n != ERR ) {
  213.         if ( n == cp->now_ptr )
  214.         cp->cur_y = i;
  215.         lp = get_lin(n);
  216.         if ( no != TERM && 
  217.          lp->left == ERR && strchr(lp->lin,'\n') == NULL ) {
  218.         strcpy(tmp,lp->lin);
  219.         strcat(tmp,"[EOF]");
  220.         if ( strlen(tmp) > 80 ) {
  221.             bch = tmp[80];
  222.             tmp[80] = '\0';
  223.                 putstr(y*512,tmp);
  224.             tmp[80] = bch;
  225.             p = &(tmp[80]);
  226.         } else {
  227.             fg = TRUE;
  228.                 putstr(y*512,tmp);
  229.         }
  230.         } else
  231.             putstr(y*512,lp->lin);
  232.         n = lp->left;
  233.     } else if ( no != TERM && fg == FALSE ) {
  234.         fg = TRUE;
  235.         putstr(y*512,p);
  236.     } else
  237.         putstr(y*512,"");
  238.     y += FONT_SIZ;
  239.     }
  240.  
  241.     if ( no == cur_wind )
  242.         cur_wind = ERR;
  243. }
  244.  
  245. void    WIN_dsp_now(int no)
  246. {
  247.     int     y;
  248.     WIND    *wp;
  249.     register CHI_PTR *cp;
  250.     register LIN_PTR *lp;
  251.  
  252.     wp = &(win[no]);
  253.     cp = &(wp->child[wp->now]);
  254.     wp->wrt_mode = 0;
  255.  
  256.     if ( cp->cur_y >= wp->max_y ) {
  257.     cp->cur_y = wp->max_y - 1;
  258.     WIN_dsp_buf(no);
  259.     return;
  260.     }
  261.  
  262.     if ( cp->now_ptr == ERR )
  263.     return;
  264.  
  265.     lp = get_lin(cp->now_ptr);
  266.  
  267.     if ( lp->left == ERR ) {
  268.     WIN_dsp_buf(no);
  269.     return;
  270.     }
  271.  
  272.     y = wp->wind_y + 16 + cp->cur_y * FONT_SIZ;
  273.     putstr(y*512,lp->lin);
  274.  
  275.     if ( cur_wind == no )
  276.     cur_wind = ERR;
  277. }
  278.  
  279. int    WIN_down_scrool(int no,int count)
  280. {
  281.     int     fg=ERR;
  282.     WIND    *wp;
  283.     register CHI_PTR *cp;
  284.     register LIN_PTR *lp;
  285.  
  286.     wp = &(win[no]);
  287.     cp = &(wp->child[wp->now]);
  288.     if ( cp->now_ptr == ERR )
  289.     return ERR;
  290.     lp = get_lin(cp->now_ptr);
  291.     if ( lp->left == ERR )
  292.     return ERR;
  293.  
  294.     while ( count-- > 0 ) {
  295.     cp->now_ptr = lp->left;
  296.     cp->lin_pos++;
  297.     if ( ++cp->cur_y >= wp->max_y ) {
  298.         cp->cur_y = wp->max_y - 1;
  299.         fg = FALSE;
  300.     }
  301.     lp = get_lin(cp->now_ptr);
  302.     if ( lp->left == ERR ) {
  303.         if ( no == TERM && cp->pas_flg != FALSE ) {
  304.         MOS_disp(FALSE);
  305.         WIN_dsp_pause(no,FALSE);
  306.         MOS_disp(TRUE);
  307.         cp->pas_flg = FALSE;
  308.         }
  309.         break;
  310.     }
  311.     }
  312.     return fg;
  313. }
  314.  
  315. int    WIN_up_scrool(int no,int count)
  316. {
  317.     int     fg=ERR;
  318.     WIND    *wp;
  319.     register CHI_PTR *cp;
  320.     register LIN_PTR *lp;
  321.  
  322.     wp = &(win[no]);
  323.     cp = &(wp->child[wp->now]);
  324.  
  325.     if ( cp->now_ptr == ERR )
  326.     return ERR;
  327.  
  328.     lp = get_lin(cp->now_ptr);
  329.     if ( lp->right == ERR )
  330.     return ERR;
  331.  
  332.     if ( no == TERM && cp->pas_flg == FALSE ) {
  333.     MOS_disp(FALSE);
  334.     WIN_dsp_pause(no,TRUE);
  335.     MOS_disp(TRUE);
  336.     cp->pas_flg = TRUE;
  337.     }
  338.  
  339.     while ( count-- > 0 ) {
  340.     cp->now_ptr = lp->right;
  341.     cp->lin_pos--;
  342.     if ( --cp->cur_y < 0 ) {
  343.         cp->cur_y = 0;
  344.         fg = FALSE;
  345.     }
  346.     lp = get_lin(cp->now_ptr);
  347.     if ( lp->right == ERR )
  348.         break;
  349.     }
  350.     return fg;
  351. }
  352.  
  353. int    WIN_read_file(int no,int ch,char *org_file,int sw)
  354. {
  355.     int     i,n,ct;
  356.     int     sec_flg=FALSE;
  357.     FILE    *fp;
  358.     CHI_PTR *cp;
  359.     register LIN_PTR *lp;
  360.     LIN_PTR tp;
  361.     char    *file;
  362.  
  363.     file = org_file;
  364.  
  365.     if ( secret_chk(file) ) {
  366.     if ( sw == FALSE )
  367.         return TRUE;
  368.     if ( (file = secret_file(org_file)) == NULL )
  369.         return ERR;
  370.     sec_flg = TRUE;
  371.     }
  372.  
  373.     if ( (fp = fopen(file,"r")) == NULL )
  374.     return ERR;
  375.  
  376.     lp = &tp;
  377.     n = lp->left = ERR;
  378.     ct = 0;
  379.     while ( read_line(tp.lin,fp) != NULL ) {
  380.     i = lp->left = xalloc();
  381.     lp = get_lin(lp->left);
  382.     lp->right = n;
  383.     n = i;
  384.     strcpy(lp->lin,tp.lin);
  385.     ct++;
  386.     }
  387.     fclose(fp);
  388.  
  389.     if ( sec_flg != FALSE )
  390.     unlink(file);
  391.  
  392.     if ( no >= MAX_WIND || no < 0 )
  393.     no = act_wind;
  394.     if ( ch >= CHILD_MAX || ch < 0 )
  395.     ch = win[no].now;
  396.     cp = &(win[no].child[ch]);
  397.  
  398.     if ( cp->file_name == NULL ) {
  399.     cp->file_name = strdup(org_file);
  400.         cp->sec_flg = sec_flg;
  401.     }
  402.  
  403.     if ( tp.left == ERR )
  404.     return FALSE;
  405.  
  406.     if ( cp->now_ptr == ERR ) {
  407.     cp->wrt_flg = FALSE;
  408.     cp->now_ptr = lp->left = xalloc();
  409.     cp->top_ptr = ERR;
  410.     lp = get_lin(cp->now_ptr);
  411.     lp->right = n;
  412.     lp->lin[0] = '\0';
  413.     ct++;
  414.  
  415.     } else {
  416.     cp->wrt_flg = TRUE;
  417.     lp = get_lin(cp->now_ptr);
  418.     if ( (i = lp->right) != ERR ) {
  419.         lp = get_lin(i);
  420.         lp->left = tp.left;
  421.         lp = get_lin(tp.left);
  422.         lp->right = i;
  423.     } else
  424.         cp->top_ptr = ERR;
  425.  
  426.     lp = get_lin(n);
  427.     lp->left = cp->now_ptr;
  428.     lp = get_lin(cp->now_ptr);
  429.     lp->right = n;
  430.     }
  431.  
  432.     cp->lin_max += ct;
  433.     cp->lin_pos += ct;
  434.  
  435.     if ( ct > win[no].max_y )
  436.     cp->cur_y = win[no].max_y / 2;
  437.     else
  438.     cp->cur_y = ct - 1;
  439.  
  440.     return FALSE;
  441. }
  442. int    WIN_type(int no,int ch)
  443. {
  444.     int     i,j,n,y;
  445.     WIND    *wp;
  446.     CHI_PTR *cp;
  447.     LIN_PTR *lp;
  448.     char    tmp[120];
  449.     static BLOCK *save=NULL;
  450.  
  451.     if ( no == 999 ) {
  452.     DSP_pop_vram(save);
  453.     save = NULL;
  454.     return FALSE;
  455.     }
  456.  
  457.     if ( no >= MAX_WIND || no < 0 )
  458.     no = act_wind;
  459.     if ( ch >= CHILD_MAX || ch < 0 )
  460.     ch = win[no].now;
  461.     wp = &(win[no]);
  462.     cp = &(wp->child[ch]);
  463.  
  464.     if ( cp->now_ptr == ERR )
  465.     return ERR;
  466.  
  467.     if ( cp->top_ptr == ERR ) {
  468.     n = cp->now_ptr;
  469.     while ( n != ERR ) {
  470.         cp->top_ptr = n;
  471.         lp = get_lin(n);
  472.         n = lp->right;
  473.     }
  474.     }
  475.  
  476.     if ( (j = macval("TYPELINE")) <= 0 )
  477.     j = 8;
  478.     y = 28 - j;
  479.  
  480.     if ( save == NULL )
  481.         save = DSP_push_vram(0,y*16,639,463);
  482.  
  483.     sprintf(tmp,"%s %s %s",win_name[no],child_name[ch],
  484.     cp->file_name == NULL ? "":cp->file_name);
  485.  
  486.     i = 320 - strlen(tmp) * 4;
  487.     DSP_box(0,y*16,639,y*16+15,COL_LINE,wind_col[no]);
  488.     DSP_string(tmp,i,y*16+4,wind_col2[no],wind_col[no]);
  489.  
  490.     n = cp->top_ptr;
  491.  
  492.     for ( i = 0 ; i < j && n != ERR ; i++ ) {
  493.     lp = get_lin(n);
  494.     putstr((i+y+1)*16*512,lp->lin);
  495.     n = lp->left;
  496.     }
  497.     for ( ; i < j ; i++ )
  498.     putstr((i+y+1)*16*512,"");
  499.  
  500.     return FALSE;
  501. }
  502. char    *WIN_file_chk(int no,int ch)
  503. {
  504.     CHI_PTR *cp;
  505.  
  506.     if ( no >= MAX_WIND || no < 0 )
  507.     no = act_wind;
  508.     if ( ch >= CHILD_MAX || ch < 0 )
  509.     ch = win[no].now;
  510.  
  511.     cp = &(win[no].child[ch]);
  512.     return cp->file_name;
  513. }
  514. char    *WIN_get_line(int no,int ch)
  515. {
  516.     CHI_PTR *cp;
  517.     LIN_PTR *lp;
  518.  
  519.     if ( no >= MAX_WIND || no < 0 )
  520.     no = act_wind;
  521.     if ( ch >= CHILD_MAX || ch < 0 )
  522.     ch = win[no].now;
  523.  
  524.     cp = &(win[no].child[ch]);
  525.     if ( cp->now_ptr == ERR )
  526.     return "";
  527.     lp = get_lin(cp->now_ptr);
  528.     return lp->lin;
  529. }
  530. int    WIN_secret_chk(int no,int ch)
  531. {
  532.     CHI_PTR *cp;
  533.  
  534.     if ( no >= MAX_WIND || no < 0 )
  535.     no = act_wind;
  536.     if ( ch >= CHILD_MAX || ch < 0 )
  537.     ch = win[no].now;
  538.  
  539.     cp = &(win[no].child[ch]);
  540.     return cp->sec_flg;
  541. }
  542. int    WIN_write_chk(int no,int ch)
  543. {
  544.     CHI_PTR *cp;
  545.  
  546.     if ( no >= MAX_WIND || no < 0 )
  547.     no = act_wind;
  548.     if ( ch >= CHILD_MAX || ch < 0 )
  549.     ch = win[no].now;
  550.  
  551.     cp = &(win[no].child[ch]);
  552.     return cp->wrt_flg;
  553. }
  554. int    WIN_write_file(int no,int ch,char *file,int sw)
  555. {
  556.     int     n,fg=FALSE;
  557.     FILE    *fp;
  558.     WIND    *wp;
  559.     CHI_PTR *cp;
  560.     LIN_PTR *lp;
  561.     char    *p;
  562.  
  563.     if ( no >= MAX_WIND || no < 0 )
  564.     no = act_wind;
  565.     if ( ch >= CHILD_MAX || ch < 0 )
  566.     ch = win[no].now;
  567.  
  568.     wp = &(win[no]);
  569.     cp = &(wp->child[ch]);
  570.  
  571.     if ( cp->now_ptr == ERR )
  572.     return ERR;
  573.  
  574.     if ( sw != 0 ) {
  575.     if ( secret_chk(file) ) {
  576.         if ( sw == 1 )
  577.         return TRUE;
  578.         if ( (p = secret_file(file)) == NULL )
  579.         return ERR;
  580.         fg = TRUE;
  581.     } else
  582.         p = file;
  583.     if ( (fp = fopen(p,"r+")) == NULL )
  584.         return ERR;
  585.     eof_chk(fp);
  586.  
  587.     } else if ( (fp = fopen(file,"w")) == NULL )
  588.     return ERR;
  589.  
  590.     n = cp->now_ptr;
  591.     while ( n != ERR ) {
  592.     cp->top_ptr = n;
  593.     lp = get_lin(n);
  594.     n = lp->right;
  595.     }
  596.  
  597.     for ( n = cp->top_ptr ; n != ERR ; ) {
  598.     lp = get_lin(n);
  599.     fputs(lp->lin,fp);
  600.     n = lp->left;
  601.     }
  602.     fclose(fp);
  603.  
  604.     if ( fg != FALSE ) {
  605.     unlink(file);
  606.     rename(p,file);
  607.     }
  608.  
  609.     cp->wrt_flg = FALSE;
  610.     return FALSE;
  611. }
  612. int    WIN_top_ptr(int no)
  613. {
  614.     int     i,n;
  615.     WIND    *wp;
  616.     CHI_PTR *cp;
  617.     LIN_PTR *lp;
  618.  
  619.     wp = &(win[no]);
  620.     cp = &(wp->child[wp->now]);
  621.  
  622.     if ( cp->top_ptr != ERR )
  623.     return cp->top_ptr;
  624.  
  625.     i = 0;
  626.     n = cp->now_ptr;
  627.     while ( n != ERR ) {
  628.     cp->top_ptr = n;
  629.     lp = get_lin(n);
  630.     n = lp->right;
  631.     i++;
  632.     }
  633.     cp->lin_pos = i;
  634.     return cp->top_ptr;
  635. }
  636. void    WIN_puts(no,str)
  637. int     no;
  638. char    *str;
  639. {
  640.     int     i,j,n,fg;
  641.     WIND    *wp;
  642.     CHI_PTR *cp;
  643.     LIN_PTR *lp;
  644.     LIN_PTR *tp;
  645.     char    *p,*s;
  646.     char    tmp[162];
  647.  
  648.     wp = &(win[no]);
  649.     cp = &(wp->child[wp->now]);
  650.     cp->wrt_flg = TRUE;
  651.     if ( cp->now_ptr == ERR ) {
  652.         cp->now_ptr = xalloc();
  653.         lp = get_lin(cp->now_ptr);
  654.         lp->lin[0] = '\0';
  655.     cp->lin_max++;
  656.     wp->wrt_mode = 3;
  657.     cp->top_ptr = ERR;
  658.     }
  659.     lp = get_lin(cp->now_ptr);
  660.  
  661.     s = lp->lin;
  662.     p = tmp;
  663.  
  664.     n = cp->cur_x;
  665.     while ( n-- > 0 ) {
  666.         if ( *s == '\n' || *s == '\0' )
  667.             *(p++) = ' ';
  668.         else if ( iskan(s) ) {
  669.             if ( n > 0 ) {
  670.                 *(p++) = *(s++);
  671.                 *(p++) = *(s++);
  672.                 n--;
  673.             } else if ( !wp->ins_mode ) {
  674.         *(s++) = ' ';
  675.         *s = ' ';
  676.                 *(p++) = ' ';
  677.             } else
  678.                 cp->cur_x--;
  679.          } else
  680.             *(p++) = *(s++);
  681.     }
  682.  
  683.     while ( *str != '\0' ) {
  684.         *(p++) = *(str++);
  685.         cp->cur_x++;
  686.         if ( !wp->ins_mode ) {
  687.             if ( iskan(s) ) {
  688.                 *(s++) = ' ';
  689.                 *s = ' ';
  690.             } else if ( *s != '\n' && *s != '\0' )
  691.                 *(s++) = ' ';
  692.         }
  693.     }
  694.  
  695.     while ( *s != '\0' )
  696.         *(p++) = *(s++);
  697.  
  698.     *p = '\0';
  699.  
  700.     if ( strlen(tmp) >= 80 ) {
  701.         n = 0;
  702.         s = tmp;
  703.         p = lp->lin;
  704.         while ( n < 80 && *s != '\0' ) {
  705.             if ( iskan(s) ) {
  706.                 if ( n == 79 )
  707.                     break;
  708.                 *(p++) = *(s++);
  709.                 *(p++) = *(s++);
  710.                 n += 2;
  711.             } else {
  712.                 *(p++) = *(s++);
  713.                 n++;
  714.             }
  715.         }
  716.         *p = '\0';
  717.  
  718.         if ( cp->cur_x >= n ) {
  719.             cp->cur_x -= n;
  720.             if ( ++cp->cur_y >= wp->max_y )
  721.                 cp->cur_y = wp->max_y - 1;
  722.             fg = TRUE;
  723.         } else
  724.             fg = FALSE;
  725.  
  726.         if ( (p = strchr(s,'\n')) != NULL || lp->left == ERR ) {
  727.             n = xalloc();
  728.             tp = get_lin(n);
  729.             tp->right = cp->now_ptr;
  730.             tp->left = lp->left;
  731.             lp->left = n;
  732.             if ( tp->left != ERR ) {
  733.                 lp = get_lin(tp->left);
  734.                 lp->right = n;
  735.                 lp = get_lin(cp->now_ptr);
  736.             }
  737.             strcpy(tp->lin,s);
  738.         cp->lin_max++;
  739.  
  740.         } else {
  741.         i = cp->now_ptr;
  742.             cp->now_ptr = lp->left;
  743.             n = cp->cur_x;
  744.             cp->cur_x = 0;
  745.         j = cp->lin_pos;
  746.             WIN_puts(no,s);
  747.         cp->now_ptr = i;
  748.             cp->cur_x = n;
  749.         cp->lin_pos = j;
  750.         }
  751.  
  752.         if ( fg ) {
  753.             cp->now_ptr = lp->left;
  754.         cp->lin_pos++;
  755.     }
  756.  
  757.         if ( wp->wrt_mode < 3 )
  758.             wp->wrt_mode = 3;
  759.  
  760.     } else {
  761.         strcpy(lp->lin,tmp);
  762.  
  763.         if ( wp->wrt_mode < 2 )
  764.             wp->wrt_mode = 2;
  765.     }
  766. }
  767.  
  768. void    WIN_ins_line(no)
  769. int     no;
  770. {
  771.     int     n;
  772.     WIND    *wp;
  773.     CHI_PTR *cp;
  774.     LIN_PTR *lp;
  775.     LIN_PTR *tp;
  776.  
  777.     wp = &(win[no]);
  778.     cp = &(wp->child[wp->now]);
  779.     cp->wrt_flg = TRUE;
  780.     if ( cp->now_ptr == ERR ) {
  781.         cp->now_ptr = xalloc();
  782.         lp = get_lin(cp->now_ptr);
  783.         lp->lin[0] = '\0';
  784.     cp->lin_max++;
  785.     wp->wrt_mode = 3;
  786.     cp->top_ptr = ERR;
  787.     }
  788.  
  789.     lp = get_lin(cp->now_ptr);
  790.     n = xalloc();
  791.     tp = get_lin(n);
  792.     tp->lin[0] = '\0';
  793.  
  794.     tp->right = cp->now_ptr;
  795.     tp->left = lp->left;
  796.     lp->left = n;
  797.     if ( tp->left != ERR ) {
  798.     strcpy(tp->lin,"\n");
  799.         lp = get_lin(tp->left);
  800.         lp->right = n;
  801.     } else if ( strchr(lp->lin,'\n') == NULL )
  802.     strcat(lp->lin,"\n");
  803.  
  804.     cp->lin_max++;
  805.     wp->wrt_mode = 3;
  806. }
  807. void    WIN_putc(int no,int ch)
  808. {
  809.     int     i,n;
  810.     WIND    *wp;
  811.     register CHI_PTR *cp;
  812.     register LIN_PTR *lp;
  813.     char    tmp[TAB+1];
  814.  
  815.     wp = &(win[no]);
  816.     cp = &(wp->child[wp->now]);
  817.     if ( cp->now_ptr != ERR )
  818.     lp = get_lin(cp->now_ptr);
  819.  
  820.     if ( cp->bak_cod != '\0' ) {
  821.     tmp[0] = cp->bak_cod;
  822.     cp->bak_cod = '\0';
  823.     if ( iskanji2(ch) ) {
  824.         tmp[1] = ch;
  825.         tmp[2] = '\0';
  826.         WIN_puts(no,tmp);
  827.         return;
  828.     } else {
  829.         tmp[1] = '\0';
  830.         WIN_puts(no,tmp);
  831.     }
  832.     }
  833.  
  834.     switch(ch) {
  835.     case '\x0D':
  836.     cp->cur_x = 0;
  837.     break;
  838.  
  839.     case '\x0A':
  840.     if ( cp->now_ptr != ERR ) {
  841.         macset("PARA",lp->lin);
  842.         MSG_wind("line_chk");
  843.     }
  844.     if ( cp->now_ptr == ERR || lp->left == ERR || wp->ins_mode )
  845.         WIN_ins_line(no);
  846.     if ( down_fp != NULL )
  847.         fputs(lp->lin,down_fp);
  848.     if ( WIN_down_scrool(no,1) != ERR )
  849.         wp->wrt_mode = 3;
  850.  
  851.     if ( log_max > 5000 )
  852.         break;
  853.  
  854.     WIN_top_ptr(no);
  855.     while ( cp->lin_max >= log_max ) {
  856.         if ( cp->top_ptr == ERR || cp->top_ptr == cp->now_ptr )
  857.         break;
  858.         lp = get_lin(cp->top_ptr);
  859.         if ( (n = lp->left) == ERR )
  860.         break;
  861.         xfree(cp->top_ptr);
  862.         cp->top_ptr = n;
  863.         cp->lin_max--;
  864.     }
  865.     if ( cp->top_ptr != ERR ) {
  866.         lp = get_lin(cp->top_ptr);
  867.         lp->right = ERR;
  868.     }
  869.     break;
  870.  
  871.     case '\x09':
  872.     n = TAB - (cp->cur_x % TAB);
  873.     for ( i = 0 ; i < n ; i++ )
  874.         tmp[i] = ' ';
  875.     tmp[i] = '\0';
  876.     WIN_puts(no,tmp);
  877.     break;
  878.  
  879.     case '\x08':
  880.     if ( cp->cur_x > 0 )
  881.         cp->cur_x--;
  882.     else {
  883.         cp->cur_x = 79;
  884.         if ( cur_y > 0 )
  885.         cp->cur_y--;
  886.         if ( cp->now_ptr != ERR && lp->right != ERR ) {
  887.         cp->now_ptr = lp->right;
  888.         cp->lin_pos--;
  889.         }
  890.     }
  891.     break;
  892.  
  893.     case '\x07':
  894.     MSG_wind("beep");
  895.     break;
  896.  
  897.     default:
  898.     if ( iskanji(ch) )
  899.         cp->bak_cod = ch;
  900.     else if ( ch != '\0' ) {
  901.         tmp[0] = ch;
  902.         tmp[1] = '\0';
  903.         WIN_puts(no,tmp);
  904.     }
  905.     break;
  906.     }
  907. }
  908. int    WIN_flush(int no)
  909. {
  910.     WIND    *wp;
  911.  
  912.     wp = &(win[no]);
  913.     if ( wp->open_flg == FALSE )
  914.     return FALSE;
  915.  
  916.     switch(wp->wrt_mode) {
  917.     case 0:
  918.     case 1:
  919.     return FALSE;
  920.  
  921.     case 2:
  922.     MOS_disp(FALSE);
  923.     WIN_dsp_now(no);
  924.     MOS_disp(TRUE);
  925.     break;
  926.  
  927.     case 3:
  928.     MOS_disp(FALSE);
  929.     WIN_dsp_buf(no);
  930.     MOS_disp(TRUE);
  931.     break;
  932.     }
  933.  
  934.     return TRUE;
  935. }
  936. void    TERM_pause_abort(void)
  937. {
  938.     register WIND    *wp;
  939.     register CHI_PTR *cp;
  940.     LIN_PTR  *lp;
  941.  
  942.     wp = &(win[TERM]);
  943.     cp = &(wp->child[wp->now]);
  944.     if ( cp->now_ptr != ERR ) {
  945.     do {
  946.         WIN_down_scrool(TERM,9999);
  947.         wp->wrt_mode = 3;
  948.         lp = get_lin(cp->now_ptr);
  949.     } while ( lp->left != ERR );
  950.     }
  951. }
  952. void    DEL_line(void)
  953. {
  954.     int     n;
  955.     WIND    *wp;
  956.     CHI_PTR *cp;
  957.     LIN_PTR *lp;
  958.     LIN_PTR *tp;
  959.  
  960.     wp = &(win[act_wind]);
  961.     cp = &(wp->child[wp->now]);
  962.     if ( (n = cp->now_ptr) == ERR )
  963.     return;
  964.     cp->wrt_flg = TRUE;
  965.     lp = get_lin(cp->now_ptr);
  966.  
  967.     if ( lp->left != ERR ) {
  968.     strcpy(undo,lp->lin);
  969.     tp = get_lin(lp->left);
  970.     tp->right = lp->right;
  971.     if ( lp->right != ERR ) {
  972.         tp = get_lin(lp->right);
  973.         tp->left = lp->left;
  974.     } else
  975.         cp->top_ptr = ERR;
  976.     cp->now_ptr = lp->left;
  977.     xfree(n);
  978.     cp->lin_max--;
  979.     wp->wrt_mode = 3;
  980.  
  981.     } else if ( lp->right != ERR ) {
  982.     lp->lin[0] = '\0';
  983.     wp->wrt_mode = 3;
  984.     
  985.     } else {
  986.     xfree(cp->now_ptr);
  987.     cp->top_ptr = cp->now_ptr = ERR;
  988.     cp->lin_max = 0;
  989.     cp->lin_pos = 0;
  990.     wp->wrt_mode = 3;
  991.     }
  992. }
  993.  
  994. void    WIN_merge(void)
  995. {
  996.     int     n,now,nxt;
  997.     WIND    *wp;
  998.     CHI_PTR *cp;
  999.     LIN_PTR *lp;
  1000.     LIN_PTR *tp;
  1001.     char    *p,*s;
  1002.     char    tmp[162];
  1003.  
  1004.     wp = &(win[act_wind]);
  1005.     cp = &(wp->child[wp->now]);
  1006.     if ( (now = cp->now_ptr) == ERR )
  1007.     return;
  1008.  
  1009. LOOP:
  1010.     lp = get_lin(now);
  1011.     if ( (nxt = lp->left) == ERR )
  1012.     return;
  1013.  
  1014.     tp = get_lin(nxt);
  1015.     strcpy(tmp,lp->lin);
  1016.     for ( p = tmp ; *p != '\n' && *p != '\0' ; p++ );
  1017.     strcpy(p,tp->lin);
  1018.  
  1019.     if ( strlen(tmp) < 80 ) {
  1020.     strcpy(lp->lin,tmp);
  1021.     lp->left = tp->left;
  1022.     if ( tp->left != ERR ) {
  1023.         tp = get_lin(tp->left);
  1024.         tp->right = now;
  1025.     }
  1026.     xfree(nxt);
  1027.     cp->lin_max--;
  1028.  
  1029.     } else {
  1030.         n = 0;
  1031.         s = tmp;
  1032.         p = lp->lin;
  1033.         while ( n < 80 && *s != '\0' ) {
  1034.             if ( iskan(s) ) {
  1035.                 if ( n == 79 )
  1036.                     break;
  1037.                 *(p++) = *(s++);
  1038.                 *(p++) = *(s++);
  1039.                 n += 2;
  1040.             } else {
  1041.                 *(p++) = *(s++);
  1042.                 n++;
  1043.             }
  1044.         }
  1045.         *p = '\0';
  1046.     strcpy(tp->lin,s);
  1047.     lp = tp;
  1048.     now = nxt;
  1049.     }
  1050.  
  1051.     wp->wrt_mode = 3;
  1052.  
  1053.     if ( strchr(lp->lin,'\n') == NULL )
  1054.     goto LOOP;
  1055. }
  1056.  
  1057. void    KEY_cr(void)
  1058. {
  1059.     int     n;
  1060.     WIND    *wp;
  1061.     CHI_PTR *cp;
  1062.     LIN_PTR *lp;
  1063.     LIN_PTR *tp;
  1064.     char    *p;
  1065.  
  1066.     wp = &(win[act_wind]);
  1067.     cp = &(wp->child[wp->now]);
  1068.     cp->wrt_flg = TRUE;
  1069.     if ( cp->now_ptr == ERR ) {
  1070.         cp->now_ptr = xalloc();
  1071.         lp = get_lin(cp->now_ptr);
  1072.         lp->lin[0] = '\0';
  1073.     cp->lin_max++;
  1074.     wp->wrt_mode = 3;
  1075.     }
  1076.  
  1077.     if ( wp->ins_mode == FALSE ) {
  1078.     cp->cur_x = 0;
  1079.     lp = get_lin(cp->now_ptr);
  1080.     if ( lp->left == ERR )
  1081.         WIN_ins_line(act_wind);
  1082.     if ( WIN_down_scrool(act_wind,1) != ERR )
  1083.         wp->wrt_mode = 3;
  1084.     return;
  1085.     }
  1086.  
  1087.     WIN_ins_line(act_wind);
  1088.     lp = get_lin(cp->now_ptr);
  1089.     tp = get_lin(lp->left);
  1090.  
  1091.     p = lp->lin;
  1092.     for ( n = 0 ; n < cp->cur_x ; ) {
  1093.     if ( *p == '\n' || *p == '\0' )
  1094.         break;
  1095.     else if ( iskan(p) ) {
  1096.         if ( (n += 2) > cp->cur_x )
  1097.         break;
  1098.         p += 2;
  1099.     } else {
  1100.         p++;
  1101.         n++;
  1102.     }
  1103.     }
  1104.  
  1105.     if ( *p != '\n' ) {
  1106.     strcpy(tp->lin,p);
  1107.     strcpy(p,"\n");
  1108.     }
  1109.  
  1110.     cp->cur_x = 0;
  1111.     WIN_down_scrool(act_wind,1);
  1112.     lp = get_lin(cp->now_ptr);
  1113.     if ( strchr(lp->lin,'\n') == NULL )
  1114.     WIN_merge();
  1115. }
  1116. void    KEY_del(void)
  1117. {
  1118.     int     n,fg=FALSE;
  1119.     WIND    *wp;
  1120.     CHI_PTR *cp;
  1121.     LIN_PTR *lp;
  1122.     char    *p,*s;
  1123.     char    tmp[82];
  1124.  
  1125.     wp = &(win[act_wind]);
  1126.     cp = &(wp->child[wp->now]);
  1127.     if ( cp->now_ptr == ERR )
  1128.     return;
  1129.  
  1130.     cp->wrt_flg = TRUE;
  1131.     lp = get_lin(cp->now_ptr);
  1132.  
  1133.     s = lp->lin;
  1134.     p = tmp;
  1135.     n = cp->cur_x;
  1136.  
  1137.     while ( n-- > 0 ) {
  1138.         if ( *s == '\n' || *s == '\0' )
  1139.             *(p++) = ' ';
  1140.         else if ( iskan(s) ) {
  1141.             if ( n > 0 ) {
  1142.                 *(p++) = *(s++);
  1143.                 *(p++) = *(s++);
  1144.                 n--;
  1145.             } else
  1146.                 cp->cur_x--;
  1147.          } else
  1148.             *(p++) = *(s++);
  1149.     }
  1150.  
  1151.     if ( iskan(s) )
  1152.     s += 2;
  1153.     else if ( *s != '\n' && *s != '\0' )
  1154.     s++;
  1155.     else
  1156.     fg = TRUE;
  1157.  
  1158.     while ( *s != '\0' )
  1159.         *(p++) = *(s++);
  1160.  
  1161.     *p = '\0';
  1162.  
  1163.     strcpy(lp->lin,tmp);
  1164.  
  1165.     if ( tmp[0] == '\n' && lp->left == ERR && lp->right == ERR )
  1166.     DEL_line();
  1167.  
  1168.     else if ( fg != FALSE || strchr(lp->lin,'\n') == NULL )
  1169.     WIN_merge();
  1170.  
  1171.     if ( wp->wrt_mode < 2 )
  1172.     wp->wrt_mode = 2;
  1173. }
  1174. void    KEY_del_left(void)
  1175. {
  1176.     int     n;
  1177.     WIND    *wp;
  1178.     CHI_PTR *cp;
  1179.     LIN_PTR *lp;
  1180.  
  1181.     wp = &(win[act_wind]);
  1182.     cp = &(wp->child[wp->now]);
  1183.     if ( cp->now_ptr == ERR )
  1184.     return;
  1185.  
  1186.     lp = get_lin(cp->now_ptr);
  1187.     if ( cp->cur_x >= strlen(lp->lin) )
  1188.     return;
  1189.  
  1190.     cp->wrt_flg = TRUE;
  1191.     n = kan_pos(lp->lin,cp->cur_x);
  1192.     if ( strchr(lp->lin,'\n') == NULL ) {
  1193.     lp->lin[n] = '\0';
  1194.     WIN_merge();
  1195.     wp->wrt_mode = 3;
  1196.  
  1197.     } else {
  1198.     lp->lin[n++] = '\n';
  1199.     lp->lin[n] = '\0';
  1200.         if ( wp->wrt_mode < 2 )
  1201.         wp->wrt_mode = 2;
  1202.     }
  1203. }
  1204. void    KEY_del_right(void)
  1205. {
  1206.     int     n;
  1207.     WIND    *wp;
  1208.     CHI_PTR *cp;
  1209.     LIN_PTR *lp;
  1210.  
  1211.     wp = &(win[act_wind]);
  1212.     cp = &(wp->child[wp->now]);
  1213.     if ( cp->now_ptr == ERR )
  1214.     return;
  1215.  
  1216.     lp = get_lin(cp->now_ptr);
  1217.     if ( cp->cur_x == 0 )
  1218.     return;
  1219.  
  1220.     cp->wrt_flg = TRUE;
  1221.     for ( n = 0 ; n < cp->cur_x ; ) {
  1222.     if ( lp->lin[n] == '\n' || lp->lin[n] == '\0' )
  1223.         break;
  1224.     else if ( iskan(&(lp->lin[n])) )
  1225.         n += 2;
  1226.     else
  1227.         n++;
  1228.     }
  1229.  
  1230.     cp->cur_x = 0;
  1231.     strcpy(lp->lin,&(lp->lin[n]));
  1232.     if ( strchr(lp->lin,'\n') == NULL ) {
  1233.     WIN_merge();
  1234.     wp->wrt_mode = 3;
  1235.     } else if ( wp->wrt_mode < 2 )
  1236.     wp->wrt_mode = 2;
  1237. }
  1238. void    INS_line(void)
  1239. {
  1240.     WIN_ins_line(act_wind);
  1241.     WIN_down_scrool(act_wind,1);
  1242.     KEY_line_top();
  1243. }
  1244. void    KEY_undo(void)
  1245. {
  1246.     int     n;
  1247.     WIND    *wp;
  1248.     CHI_PTR *cp;
  1249.     LIN_PTR *lp;
  1250.     LIN_PTR *tp;
  1251.     LIN_PTR *bp;
  1252.  
  1253.     if ( undo[0] == '\0' )
  1254.     return;
  1255.  
  1256.     wp = &(win[act_wind]);
  1257.     cp = &(wp->child[wp->now]);
  1258.  
  1259.     if ( cp->now_ptr == ERR ) {
  1260.         cp->now_ptr = xalloc();
  1261.         lp = get_lin(cp->now_ptr);
  1262.         lp->lin[0] = '\0';
  1263.     cp->lin_max = 1;
  1264.     cp->lin_pos = 0;
  1265.     cp->top_ptr = ERR;
  1266.     }
  1267.  
  1268.     n = xalloc();
  1269.     tp = get_lin(n);
  1270.     strcpy(tp->lin,undo);
  1271.  
  1272.     lp = get_lin(cp->now_ptr);
  1273.     if ( (tp->right = lp->right) != ERR ) {
  1274.     bp = get_lin(tp->right);
  1275.     bp->left = n;
  1276.     } else
  1277.     cp->top_ptr = ERR;
  1278.  
  1279.     lp->right = n;
  1280.     tp->left = cp->now_ptr;
  1281.     cp->now_ptr = n;
  1282.  
  1283.     wp->wrt_mode = 3;
  1284.     cp->lin_max++;
  1285.     cp->wrt_flg = FALSE;
  1286. }
  1287. void    KEY_tab(void)
  1288. {
  1289.     WIN_putc(act_wind,0x09);
  1290. }
  1291. void    KEY_up(void)
  1292. {
  1293.     if ( WIN_up_scrool(act_wind,1) != ERR )
  1294.     win[act_wind].wrt_mode = 3;
  1295. }
  1296. void    KEY_down(void)
  1297. {
  1298.     if ( WIN_down_scrool(act_wind,1) != ERR )
  1299.     win[act_wind].wrt_mode = 3;
  1300. }
  1301. void    KEY_scr_up(void)
  1302. {
  1303.     WIND    *wp;
  1304.     CHI_PTR *cp;
  1305.     LIN_PTR *lp;
  1306.  
  1307.     wp = &(win[act_wind]);
  1308.     cp = &(wp->child[wp->now]);
  1309.     if ( cp->now_ptr == ERR )
  1310.     return;
  1311.     lp = get_lin(cp->now_ptr);
  1312.     if ( lp->left == ERR )
  1313.     return;
  1314.     cp->now_ptr = lp->left;
  1315.     cp->lin_pos++;
  1316.     wp->wrt_mode = 3;
  1317. }
  1318. void    KEY_scr_down(void)
  1319. {
  1320.     WIND    *wp;
  1321.     CHI_PTR *cp;
  1322.     LIN_PTR *lp;
  1323.  
  1324.     wp = &(win[act_wind]);
  1325.     cp = &(wp->child[wp->now]);
  1326.     if ( cp->now_ptr == ERR )
  1327.     return;
  1328.     lp = get_lin(cp->now_ptr);
  1329.     if ( lp->right == ERR )
  1330.     return;
  1331.     cp->now_ptr = lp->right;
  1332.     cp->lin_pos--;
  1333.     wp->wrt_mode = 3;
  1334. }
  1335. void    KEY_page_up(void)
  1336. {
  1337.     if ( WIN_up_scrool(act_wind,10) != ERR )
  1338.     win[act_wind].wrt_mode = 3;
  1339. }
  1340. void    KEY_page_down(void)
  1341. {
  1342.     if ( WIN_down_scrool(act_wind,10) != ERR )
  1343.     win[act_wind].wrt_mode = 3;
  1344. }
  1345. void    KEY_left(void)
  1346. {
  1347.     WIND    *wp;
  1348.     CHI_PTR *cp;
  1349.     LIN_PTR *lp;
  1350.     char    *p;
  1351.  
  1352.     wp = &(win[act_wind]);
  1353.     cp = &(wp->child[wp->now]);
  1354.     if ( --cp->cur_x < 0 ) {
  1355.     KEY_up();
  1356.     if ( cp->now_ptr != ERR ) {
  1357.         lp = get_lin(cp->now_ptr);
  1358.         cp->cur_x = 0;
  1359.         for ( p = lp->lin ; *p != '\n' && *p != '\0' ; p++ )
  1360.             cp->cur_x++;
  1361.         if ( cp->cur_x >= 80 )
  1362.         cp->cur_x = 79;
  1363.     } else
  1364.         cp->cur_x = 79;
  1365.  
  1366.     } else if ( cp->now_ptr != ERR ) {
  1367.     lp = get_lin(cp->now_ptr);
  1368.     if ( cp->cur_x < strlen(lp->lin) )
  1369.         cp->cur_x = kan_pos(lp->lin,cp->cur_x);
  1370.     }
  1371. }
  1372. void    KEY_right(void)
  1373. {
  1374.     WIND    *wp;
  1375.     CHI_PTR *cp;
  1376.     LIN_PTR *lp;
  1377.  
  1378.     wp = &(win[act_wind]);
  1379.     cp = &(wp->child[wp->now]);
  1380.     if ( ++cp->cur_x >= 80 ) {
  1381.     cp->cur_x = 0;
  1382.     KEY_down();
  1383.     } else if ( cp->now_ptr != ERR ) {
  1384.     lp = get_lin(cp->now_ptr);
  1385.     if ( cp->cur_x < strlen(lp->lin) && 
  1386.          cp->cur_x != kan_pos(lp->lin,cp->cur_x) )
  1387.         cp->cur_x++;
  1388.     }
  1389. }
  1390. void    KEY_line_top(void)
  1391. {
  1392.     WIND    *wp;
  1393.     CHI_PTR *cp;
  1394.  
  1395.     wp = &(win[act_wind]);
  1396.     cp = &(wp->child[wp->now]);
  1397.     cp->cur_x = 0;
  1398. }
  1399. void    KEY_line_btm(void)
  1400. {
  1401.     WIND    *wp;
  1402.     CHI_PTR *cp;
  1403.     LIN_PTR *lp;
  1404.     char    *p;
  1405.  
  1406.     wp = &(win[act_wind]);
  1407.     cp = &(wp->child[wp->now]);
  1408.     if ( cp->now_ptr != ERR ) {
  1409.     lp = get_lin(cp->now_ptr);
  1410.     cp->cur_x = 0;
  1411.     for ( p = lp->lin ; *p != '\n' && *p != '\0' ; p++ )
  1412.         cp->cur_x++;
  1413.     if ( cp->cur_x >= 80 )
  1414.         cp->cur_x = 79;
  1415.     } else
  1416.     cp->cur_x = 79;
  1417. }
  1418. void    KEY_word_right(void)
  1419. {
  1420.     int     n,len,fg;
  1421.     WIND    *wp;
  1422.     CHI_PTR *cp;
  1423.     LIN_PTR *lp;
  1424.  
  1425.     wp = &(win[act_wind]);
  1426.     cp = &(wp->child[wp->now]);
  1427.     if ( cp->now_ptr == ERR )
  1428.     return;
  1429.  
  1430.     lp = get_lin(cp->now_ptr);
  1431.     len = strlen(lp->lin);
  1432.     fg = (cp->cur_x >= len ? 1:0);
  1433.  
  1434.     for ( ; ; ) {
  1435.     while ( cp->cur_x >= len ) {
  1436.         if ( lp->left == ERR )
  1437.         return;
  1438.         cp->cur_x = 0;
  1439.         if ( ++cp->cur_y >= wp->max_y ) {
  1440.         cp->cur_y = wp->max_y - 1;
  1441.         wp->wrt_mode = 3;
  1442.         }
  1443.         cp->now_ptr = lp->left;
  1444.         cp->lin_pos++;
  1445.         lp = get_lin(cp->now_ptr);
  1446.         len = strlen(lp->lin);
  1447.     }
  1448.     n = kan_pos(lp->lin,cp->cur_x);
  1449.     if ( fg == 0 && lp->lin[n] < '0' )
  1450.         fg = 1;
  1451.     if ( fg != 0 && lp->lin[n] >= '0' )
  1452.         break;
  1453.     cp->cur_x = n + (iskan(&(lp->lin[n])) ? 2:1);
  1454.     }
  1455. }
  1456. void    KEY_word_left(void)
  1457. {
  1458.     int     n,len,fg;
  1459.     WIND    *wp;
  1460.     CHI_PTR *cp;
  1461.     LIN_PTR *lp;
  1462.  
  1463.     wp = &(win[act_wind]);
  1464.     cp = &(wp->child[wp->now]);
  1465.     if ( cp->now_ptr == ERR )
  1466.     return;
  1467.  
  1468.     lp = get_lin(cp->now_ptr);
  1469.     len = strlen(lp->lin);
  1470.  
  1471.     for ( fg = 0 ; ; ) {
  1472.     while ( cp->cur_x < 0 ) {
  1473.         cp->cur_x = 0;
  1474.         if ( lp->right == ERR )
  1475.         return;
  1476.         if ( cp->cur_y > 0 )
  1477.         cp->cur_y--;
  1478.         else
  1479.         wp->wrt_mode = 3;
  1480.         cp->now_ptr = lp->right;
  1481.         cp->lin_pos--;
  1482.         lp = get_lin(cp->now_ptr);
  1483.         len = strlen(lp->lin);
  1484.         cp->cur_x = len - 1;
  1485.     }
  1486.     n = kan_pos(lp->lin,cp->cur_x);
  1487.     if ( fg == 0 && lp->lin[n] < '0' )
  1488.         fg = 1;
  1489.     if ( fg == 1 && lp->lin[n] >= '0' )
  1490.         fg = 2;
  1491.     if ( fg == 2 && lp->lin[n] < '0' ) {
  1492.         if ( ++cp->cur_x >= len )
  1493.             KEY_word_right();
  1494.         break;
  1495.     }
  1496.     cp->cur_x = n-1;
  1497.     }
  1498. }
  1499. void    KEY_bs(void)
  1500. {
  1501.     WIND    *wp;
  1502.     CHI_PTR *cp;
  1503.     LIN_PTR *lp;
  1504.     char    *p;
  1505.  
  1506.     wp = &(win[act_wind]);
  1507.     cp = &(wp->child[wp->now]);
  1508.     if ( cp->now_ptr == ERR )
  1509.     return;
  1510.  
  1511.     if ( --cp->cur_x < 0 ) {
  1512.     KEY_up();
  1513.     lp = get_lin(cp->now_ptr);
  1514.     cp->cur_x = 0;
  1515.     for ( p = lp->lin ; *p != '\n' && *p != '\0' ; p++ )
  1516.         cp->cur_x++;
  1517.     if ( cp->cur_x >= 80 )
  1518.         cp->cur_x = 79;
  1519.     wp->wrt_mode = 3;
  1520.     }
  1521.     KEY_del();
  1522. }
  1523. void    KEY_ins_sw(void)
  1524. {
  1525.     WIND    *wp;
  1526.  
  1527.     wp = &(win[act_wind]);
  1528.     wp->ins_mode = (wp->ins_mode == FALSE ? TRUE:FALSE);
  1529. }
  1530. void    KEY_act_cheng(void)
  1531. {
  1532.      int     i,n;
  1533.  
  1534.     if ( wind_count <= 1 )
  1535.     return;
  1536.  
  1537.     n = act_wind;
  1538.     for ( i = 0 ; i < (MAX_WIND - 1) ; i++ ) {
  1539.     if ( ++n >= MAX_WIND )
  1540.         n = 0;
  1541.     if ( win[n].open_flg != FALSE )
  1542.         break;
  1543.     }
  1544.     WIN_act_cheng(n);
  1545. }
  1546. void    KEY_mike_open(void)
  1547. {
  1548.     WIN_open(0);
  1549. }
  1550. void    KEY_john_open(void)
  1551. {
  1552.     WIN_open(1);
  1553. }
  1554. void    KEY_kent_open(void)
  1555. {
  1556.     WIN_open(2);
  1557. }
  1558. void    KEY_jack_open(void)
  1559. {
  1560.     extern int top_event;
  1561.  
  1562.     top_event = 4;        /* looking for whisper.c */
  1563. }
  1564. void    TERM_cheng(int no)
  1565. {
  1566.     win[TERM].ins_mode = bak_ins_mode;
  1567.     bak_ins_mode = win[no].ins_mode;
  1568.     TERM = no;
  1569.     macvalset("TERM",no);
  1570.     TERM_pause_abort();
  1571.     win[no].ins_mode = FALSE;
  1572.     if ( up_wind == no )
  1573.     up_wind = ERR;
  1574.     WIN_resize();
  1575. }
  1576. void    KEY_term_mike(void)
  1577. {
  1578.     TERM_cheng(0);
  1579. }
  1580. void    KEY_term_john(void)
  1581. {
  1582.     TERM_cheng(1);
  1583. }
  1584. void    KEY_term_kent(void)
  1585. {
  1586.     TERM_cheng(2);
  1587. }
  1588. void    KEY_scl_dsp(void)
  1589. {
  1590.     scl_flg = (scl_flg == 0 ? 1:0);
  1591.     WIN_resize();
  1592. }
  1593. void    TANGO_set(void)
  1594. {
  1595.     if ( MSG_wind("tango_touroku") != FALSE )
  1596.     return;
  1597.     key_flg = TRUE;
  1598.     if ( memo_buf != NULL && *memo_buf != '\0' )
  1599.     KAN_touroku(strlen(memo_buf),memo_buf);
  1600. }
  1601. void    KEY_memo(void)
  1602. {
  1603.     MEMO_insrt(99,99);
  1604. }
  1605. void    KEY_for_scrool(void)
  1606. {
  1607.     int    n;
  1608.     register WIND    *wp;
  1609.     register CHI_PTR *cp;
  1610.  
  1611.     wp = &(win[act_wind]);
  1612.     cp = &(wp->child[wp->now]);
  1613.     n = wp->max_y - cp->cur_y + 5;
  1614.  
  1615.     if ( WIN_down_scrool(TERM,n) != ERR ) {
  1616.     MOS_disp(FALSE);
  1617.     WIN_dsp_buf(TERM);
  1618.     MOS_disp(TRUE);
  1619.    }
  1620. }
  1621. void    KEY_bak_scrool(void)
  1622. {
  1623.     int    n;
  1624.     register WIND    *wp;
  1625.     register CHI_PTR *cp;
  1626.  
  1627.     wp = &(win[act_wind]);
  1628.     cp = &(wp->child[wp->now]);
  1629.     n = cp->cur_y + 1 + 5;
  1630.  
  1631.     if ( WIN_up_scrool(TERM,n) != ERR ) {
  1632.     MOS_disp(FALSE);
  1633.     WIN_dsp_buf(TERM);
  1634.     MOS_disp(TRUE);
  1635.    }
  1636. }
  1637. void    WIN_up_line(void)
  1638. {
  1639.     int     n,y;
  1640.     WIND    *wp;
  1641.     CHI_PTR *cp;
  1642.     LIN_PTR *lp;
  1643.     char    *p;
  1644.     static int soft_wait=0;
  1645.  
  1646.     if ( up_wind == ERR && up_memo == ERR )
  1647.     return;
  1648.  
  1649.     if ( soft_wait > 0 ) {
  1650.     soft_wait--;
  1651.     return;
  1652.     }
  1653.  
  1654.     if ( up_memo != ERR ) {
  1655.     lp = get_lin(up_memo);
  1656.     for ( p = lp->lin ; *p != '\0' ; p++ ) {
  1657.         if ( *p == '\n' ) {
  1658.         RSB_putc(0x0D);
  1659.         soft_wait = macval("_CRWAIT");
  1660.         } else
  1661.         RSB_putc(*p);
  1662.     }
  1663.     up_memo = lp->left;
  1664.     return;
  1665.     }
  1666.  
  1667.     wp = &(win[up_wind]);
  1668.     n = wp->now;
  1669.     wp->now = up_child;
  1670.     cp = &(wp->child[wp->now]);
  1671.     lp = get_lin(cp->now_ptr);
  1672.  
  1673.     for ( p = lp->lin ; *p != '\0' ; p++ ) {
  1674.     if ( *p == '\n' ) {
  1675.         RSB_putc(0x0D);
  1676.         soft_wait = macval("_CRWAIT");
  1677.     } else
  1678.         RSB_putc(*p);
  1679.     }
  1680.  
  1681.     WIN_down_scrool(up_wind,1);
  1682.     wp->now = n;
  1683.  
  1684.     if ( lp->left == ERR ) {
  1685.     if ( wp->open_flg != FALSE && wp->now == up_child ) {
  1686.         MOS_disp(FALSE);
  1687.         WIN_dsp_buf(up_wind);
  1688.         WIN_dsp_pause(up_wind,FALSE);
  1689.         MOS_disp(TRUE);
  1690.     }
  1691.     up_wind = ERR;
  1692.     cp->pas_flg = FALSE;
  1693.  
  1694.     } else if ( wp->open_flg != FALSE && wp->now == up_child ) {
  1695.     MOS_disp(FALSE);
  1696.     WIN_dsp_buf(up_wind);
  1697.     y = cp->cur_y * FONT_SIZ + wp->wind_y + 31;
  1698.     DSP_line(0,y,639,y,COL_RED,4);
  1699.     MOS_disp(TRUE);
  1700.     }
  1701. }
  1702.  
  1703. void    WIN_term_loop(void)
  1704. {
  1705.     int     len,ch;
  1706.     CHI_PTR *cp;
  1707.  
  1708.     cp = &(win[TERM].child[win[TERM].now]);
  1709.     if ( cp->pas_flg )
  1710.     return;
  1711.  
  1712.     len = RSB_chk();
  1713.     while ( len-- > 0 ) {
  1714.     ch = RSB_getc();
  1715.     WIN_putc(TERM,ch);
  1716.     }
  1717.     WIN_flush(TERM);
  1718. }
  1719. void    LIN_onoff(void)
  1720. {
  1721.     if ( lin_flg == FALSE ) {
  1722.     lin_flg = TRUE;
  1723.     win[TERM].max_y = (win[TERM].size_y - 32) / FONT_SIZ;
  1724.     } else {
  1725.     lin_flg = FALSE;
  1726.     win[TERM].max_y = (win[TERM].size_y - 16) / FONT_SIZ;
  1727.     LIN_buf_flush();
  1728.     }
  1729.  
  1730.     MOS_disp(FALSE);
  1731.     if ( lin_flg != FALSE ) {
  1732.     DSP_xline(0,win[TERM].wind_y+16,
  1733.         639,win[TERM].wind_y+win[TERM].size_y-1,COL_BAK,0);
  1734.     LIN_buf_dsp();
  1735.     } else
  1736.     putstr((win[TERM].wind_y + win[TERM].size_y - 16)*512,"");
  1737.  
  1738.     WIN_dsp_buf(TERM);
  1739.     MOS_disp(TRUE);
  1740. }
  1741. void    WIN_loop(void)
  1742. {
  1743.     int     i,x,y,ch,n=0;
  1744.     unsigned ec;
  1745.     WIND    *wp;
  1746.     CHI_PTR *cp;
  1747.     char    tmp[84];
  1748.  
  1749.     wp = &(win[act_wind]);
  1750.     cp = &(wp->child[wp->now]);
  1751.  
  1752.     x = cur_x = cp->cur_x * 8;
  1753.     y = cur_y = cp->cur_y * FONT_SIZ + wp->wind_y + 16;
  1754.     
  1755.     if ( cp->pas_flg == FALSE )
  1756.         WIN_cursol(act_wind,x,y);
  1757.     else if ( act_wind != TERM ) {
  1758.     MSG_wind("now_upload");
  1759.     goto ENDOF;
  1760.     }
  1761.  
  1762.     if ( act_wind == TERM && lin_flg != FALSE ) {
  1763.     cur_x = LIN_buf_pos() * 8;
  1764.     cur_y = win[TERM].wind_y + win[TERM].size_y - 16;
  1765.     }
  1766.  
  1767.     while ( kbhit() ) {
  1768.     ch = getkey(&ec);
  1769.     ec &= 0xFF14;
  1770.  
  1771.     if ( act_wind == TERM ) {
  1772.         if ( TERM_KEY_exec(ec) == FALSE && ch != 0xFFFF ) {
  1773.         if ( lin_flg != FALSE )
  1774.             LIN_input(ch);
  1775.         else {
  1776.             if ( cp->pas_flg != FALSE )
  1777.                 TERM_pause_abort();
  1778.             RSB_putc(ch);
  1779.         }
  1780.         }
  1781.         continue;
  1782.     }
  1783.  
  1784.     if ( (i = EDIT_KEY_chk(ec)) != ERR ) {
  1785.         if ( n > 0 ) {
  1786.             tmp[n] = '\0';
  1787.             WIN_puts(act_wind,tmp);
  1788.         WIN_flush(act_wind);
  1789.         n = 0;
  1790.         }
  1791.         EDIT_KEY_exec(ec,i);
  1792.  
  1793.     } else if ( ch != 0xFFFF && ch >= ' ' ) {
  1794.         tmp[n++] = ch;
  1795.         if ( n >= 80 ) {
  1796.             tmp[n] = '\0';
  1797.             WIN_puts(act_wind,tmp);
  1798.         WIN_flush(act_wind);
  1799.         n = 0;
  1800.         }
  1801.     }
  1802.     }
  1803.  
  1804.     if ( n > 0 ) {
  1805.         tmp[n] = '\0';
  1806.         WIN_puts(act_wind,tmp);
  1807.     }
  1808.  
  1809. ENDOF:
  1810.     if ( lin_flg != FALSE && lin_new_flg != FALSE && 
  1811.                  win[TERM].open_flg != FALSE ) {
  1812.     MOS_disp(FALSE);
  1813.     LIN_buf_dsp();
  1814.     MOS_disp(TRUE);
  1815.     lin_new_flg = FALSE;
  1816.     }
  1817.  
  1818.     WIN_flush(act_wind);
  1819.     WIN_up_line();
  1820.     WIN_term_loop();
  1821. }
  1822. int    WIN_down_start(char *file)
  1823. {
  1824.     if ( down_fp != NULL ) {
  1825.     fclose(down_fp);
  1826.     down_fp = NULL;
  1827.     WIN_dsp_down(FALSE);
  1828.     return TRUE;
  1829.     }
  1830.  
  1831.     if ( (down_fp = fopen(file,"r+")) == NULL ) {
  1832.     if ( (down_fp = fopen(file,"w")) == NULL )
  1833.         return ERR;
  1834.     } else
  1835.     eof_chk(down_fp);
  1836.  
  1837.     WIN_dsp_down(TRUE);
  1838.     return FALSE;
  1839. }
  1840. void    WIN_upload(int no)
  1841. {
  1842.     int     n,y;
  1843.     WIND    *wp;
  1844.     CHI_PTR *cp;
  1845.  
  1846.     if ( no >= MAX_WIND )
  1847.     no = act_wind;
  1848.  
  1849.     wp = &(win[no]);
  1850.     cp = &(wp->child[wp->now]);
  1851.     if ( cp->now_ptr == ERR )
  1852.     return;
  1853.  
  1854.     if ( up_wind == no && cp->pas_flg != FALSE ) {
  1855.     up_wind = ERR;
  1856.     cp->pas_flg = FALSE;
  1857.     MOS_disp(FALSE);
  1858.     WIN_dsp_pause(no,FALSE);
  1859.     MOS_disp(TRUE);
  1860.     return;
  1861.  
  1862.     } else if ( up_wind != ERR )
  1863.     return;
  1864.  
  1865.     cp->pas_flg = TRUE;
  1866.     n = cp->now_ptr = WIN_top_ptr(no);
  1867.     cp->cur_y = cp->cur_x = 0;
  1868.     up_wind = no;
  1869.     up_child = wp->now;
  1870.     y = cp->cur_y * FONT_SIZ + wp->wind_y + 31;
  1871.  
  1872.     MOS_disp(FALSE);
  1873.     WIN_dsp_buf(no);
  1874.     WIN_dsp_pause(no,TRUE);
  1875.     DSP_line(0,y,639,y,COL_RED,4);
  1876.     MOS_disp(TRUE);
  1877.  
  1878.     TERM_pause_abort();
  1879. }
  1880.  
  1881. void    WIN_act_man(int no)
  1882. {
  1883.     DSP_string(win_name[no],WIND_X+no*40+2,4,
  1884.     (win[no].open_flg == FALSE ? COL_WHIS2:
  1885.            (no == act_wind ? COL_RED:
  1886.                (no == TERM ? COL_LOVE:COL_CHR))),COL_WHIS);
  1887. }
  1888.  
  1889. void    WIN_act_cheng(int no)
  1890. {
  1891.     int     i;
  1892.  
  1893.     macvalset("ACTWIND",no);
  1894.     macvalset("OLDWIND",act_wind);
  1895.     MSG_wind("wind_act_cheng");
  1896.  
  1897.     MOS_disp(FALSE);
  1898.     DSP_string(win_name[act_wind],
  1899.         W_NAME_X+2,win[act_wind].wind_y+4,
  1900.         COL_CHR,win[act_wind].color);
  1901.     DSP_string(win_name[no],
  1902.         W_NAME_X+2,win[no].wind_y+4,
  1903.         COL_RED,win[no].color);
  1904.     i = act_wind;
  1905.     act_wind = no;
  1906.     WIN_act_man(i);
  1907.     WIN_act_man(no);
  1908.     MOS_disp(TRUE);
  1909. }
  1910.  
  1911. void    WIN_child_dsp(int no)
  1912. {
  1913.     int     i;
  1914.     register WIND *wp;
  1915.  
  1916.     wp = &win[no];
  1917.     for ( i = 0 ; i < CHILD_MAX ; i++ ) {
  1918.     DSP_string(child_name[i],W_CHILD_X+i*24+6,wp->wind_y+4,
  1919.         wp->now == i ? COL_CHR:wind_col2[no],wp->color);
  1920.     }
  1921. }
  1922.  
  1923. void    WIN_move_event(register EVENT *ep,int x,int y)
  1924. {
  1925.     static int ofy=0,ty=0;
  1926.     static int topy=0,btmy=0;
  1927.     int     i,n;
  1928.  
  1929.     switch(ep->now) {
  1930.  
  1931.     case EVT_CLIP_MOS:
  1932.     DSP_mos(1);
  1933.     EVT_clip_on(ep);
  1934.     ofy = y - ep->y1 + 2;
  1935.     ep->now = EVT_DOLACK_MOS;
  1936.     topy = 16;
  1937.     btmy = win[ep->no].wind_y + win[ep->no].size_y - 48;
  1938.     for ( i = 0 ; i < ep->no ; i++ ) {
  1939.         if ( win[i].open_flg != FALSE )
  1940.         topy = win[i].wind_y + 48;
  1941.     }
  1942.  
  1943.     case EVT_DOLACK_MOS:
  1944.     if ( (ty = y - ofy) < topy ) {
  1945.         ty = topy;
  1946.         MOS_setpos(x,ty + ofy);
  1947.     } else if ( ty >= btmy ) {
  1948.         ty = btmy;
  1949.         MOS_setpos(x,ty + ofy);
  1950.     }
  1951.     MOS_disp(FALSE);
  1952.     DSP_line(0,ty,639,ty+15,15,4);
  1953.     DSP_line(0,ty,639,ty+15,15,4);
  1954.     MOS_disp(TRUE);
  1955.     break;
  1956.  
  1957.     case EVT_MOVE_MOS:
  1958.     case EVT_SELECT_MOS:
  1959.     case EVT_DLSEL_MOS:
  1960.     EVT_clip_off(ep);
  1961.     DSP_mos(0);
  1962.     for ( i = n = 0 ; i < ep->no ; i++ ) {
  1963.         if ( win[i].open_flg != FALSE )
  1964.         n++;
  1965.     }
  1966.     i = win_tbl[wind_count].w[n].top + win_tbl[wind_count].w[n].siz;
  1967.     win_tbl[wind_count].w[n].top = ty;
  1968.     win_tbl[wind_count].w[n].siz = i - ty;
  1969.     if ( --n >= 0 ) {
  1970.         i = ty - win_tbl[wind_count].w[n].top;
  1971.         win_tbl[wind_count].w[n].siz = i;
  1972.     }
  1973.     WIN_resize();
  1974.     break;
  1975.  
  1976.     case EVT_ON_MOS:
  1977.     DSP_mos(1);
  1978.     break;
  1979.  
  1980.     case EVT_OFF_MOS:
  1981.     DSP_mos(0);
  1982.     break;
  1983.     }
  1984. }
  1985.  
  1986. void    WIN_col_buf(int no,int pos,int len)
  1987. {
  1988.     int     i,n,y,ln,col,fg=FALSE;
  1989.     WIND    *wp;
  1990.     register CHI_PTR *cp;
  1991.     register LIN_PTR *lp;
  1992.     char    *p,bch;
  1993.     char    tmp[92];
  1994.  
  1995.     wp = &(win[no]);
  1996.     cp = &(wp->child[wp->now]);
  1997.     wp->wrt_mode = 0;
  1998.  
  1999.     n = cp->now_ptr;
  2000.     ln = cp->lin_pos;
  2001.  
  2002.     for ( i = cp->cur_y ; i > 0 && n != ERR ; i-- ) {
  2003.     lp = get_lin(n);
  2004.     ln--;
  2005.     if ( lp->right == ERR )
  2006.         break;
  2007.     n = lp->right;
  2008.     }
  2009.  
  2010.     p = strcpy(tmp,"[EOF]");
  2011.     y = wp->wind_y + 16;
  2012.     for ( i = 0 ; i < wp->max_y ; i++ ) {
  2013.     if ( ln >= pos && ln <= len )
  2014.         col = COL_LINE;
  2015.     else
  2016.         col = COL_BAK;
  2017.  
  2018.     if ( n != ERR ) {
  2019.         lp = get_lin(n);
  2020.         if ( no != TERM &&
  2021.          lp->left == ERR && strchr(lp->lin,'\n') == NULL ) {
  2022.         strcpy(tmp,lp->lin);
  2023.         strcat(tmp,"[EOF]");
  2024.         if ( strlen(tmp) > 80 ) {
  2025.             bch = tmp[80];
  2026.             tmp[80] = '\0';
  2027.             cputstr(y*512,tmp,col_cnv[COL_CHR],col_cnv[col]);
  2028.             tmp[80] = bch;
  2029.             p = &(tmp[80]);
  2030.         } else {
  2031.             fg = TRUE;
  2032.             cputstr(y*512,tmp,col_cnv[COL_CHR],col_cnv[col]);
  2033.         }
  2034.         } else
  2035.             cputstr(y*512,lp->lin,col_cnv[COL_CHR],col_cnv[col]);
  2036.         n = lp->left;
  2037.     } else if ( no != TERM && fg == FALSE ) {
  2038.         fg = TRUE;
  2039.         cputstr(y*512,p,col_cnv[COL_CHR],col_cnv[col]);
  2040.     } else
  2041.         cputstr(y*512,"",col_cnv[COL_CHR],col_cnv[col]);
  2042.  
  2043.     y += FONT_SIZ;
  2044.     ln++;
  2045.     }
  2046.  
  2047.     if ( no == cur_wind )
  2048.         cur_wind = ERR;
  2049. }
  2050. int    get_lin_pos(int no,int pos)
  2051. {
  2052.     int     n,i;
  2053.     WIND    *wp;
  2054.     CHI_PTR *cp;
  2055.     LIN_PTR *lp;
  2056.  
  2057.     wp = &(win[no]);
  2058.     cp = &(wp->child[wp->now]);
  2059.     n = cp->lin_pos;
  2060.     i = cp->now_ptr;
  2061.  
  2062.     while ( n > pos && i != ERR ) {
  2063.     lp = get_lin(i);
  2064.     if ( lp->right == ERR )
  2065.         break;
  2066.     i = lp->right;
  2067.     n--;
  2068.     }
  2069.     while ( n < pos && i != ERR ) {
  2070.     lp = get_lin(i);
  2071.     if ( lp->left == ERR )
  2072.         break;
  2073.     i = lp->left;
  2074.     n++;
  2075.     }
  2076.     return i;
  2077. }
  2078. void    WIN_ins_ptr(int no,int ch,int ptr)
  2079. {
  2080.     int     n;
  2081.     WIND    *wp;
  2082.     CHI_PTR *cp;
  2083.     LIN_PTR *lp;
  2084.     LIN_PTR *tp;
  2085.     LIN_PTR *bp;
  2086.  
  2087.     wp = &(win[no]);
  2088.     cp = &(wp->child[ch]);
  2089.  
  2090.     if ( cp->now_ptr == ERR ) {
  2091.         cp->now_ptr = xalloc();
  2092.         lp = get_lin(cp->now_ptr);
  2093.         lp->lin[0] = '\0';
  2094.     wp->wrt_mode = 3;
  2095.     cp->lin_max = 1;
  2096.     cp->lin_pos = 0;
  2097.     cp->top_ptr = ERR;
  2098.     cp->wrt_flg = TRUE;
  2099.     }
  2100.  
  2101.     while ( ptr != ERR ) {
  2102.     n = xalloc();
  2103.     tp = get_lin(n);
  2104.     bp = get_lin(ptr);
  2105.     strcpy(tp->lin,bp->lin);
  2106.     ptr = bp->left;
  2107.  
  2108.     lp = get_lin(cp->now_ptr);
  2109.     if ( (tp->right = lp->right) != ERR ) {
  2110.         bp = get_lin(tp->right);
  2111.         bp->left = n;
  2112.     } else
  2113.         cp->top_ptr = ERR;
  2114.     lp->right = n;
  2115.     tp->left = cp->now_ptr;
  2116.  
  2117.     wp->wrt_mode = 3;
  2118.     cp->lin_max++;
  2119.     cp->lin_pos++;
  2120.     cp->wrt_flg = TRUE;
  2121.     if ( cp->cur_y < (wp->max_y - 2) )
  2122.         cp->cur_y++;
  2123.     }
  2124. }
  2125. char    *MEMO_get_buf(void)
  2126. {
  2127.     if ( memo_buf != NULL )
  2128.     return memo_buf;
  2129.     return "";
  2130. }
  2131. void    MEMO_set_word(char *str)
  2132. {
  2133.     if ( memo_buf != NULL )
  2134.     free(memo_buf);
  2135.     memo_buf = strdup(str);
  2136. }
  2137. void    MEMO_insrt(int no,int ch)
  2138. {
  2139.     int     old;
  2140.     char    *p;
  2141.  
  2142.     if ( no >= MAX_WIND || no < 0 )
  2143.     no = act_wind;
  2144.     if ( ch >= CHILD_MAX || ch < 0 )
  2145.     ch = win[no].now;
  2146.  
  2147.     if ( no == TERM ) {
  2148.     if ( memo_buf != NULL ) {
  2149.         p = memo_buf;
  2150.         while ( *p != '\0' ) {
  2151.         if ( lin_flg != FALSE )
  2152.             LIN_input(*(p++));
  2153.         else
  2154.             RSB_putc(*(p++));
  2155.         }
  2156.     } else if ( memo_ptr != ERR ) {
  2157.         if ( up_memo != ERR )
  2158.         up_memo = ERR;
  2159.         else
  2160.         up_memo = memo_ptr;
  2161.     }
  2162.  
  2163.     } else {
  2164.     if ( memo_buf != NULL )
  2165.         if ( win[no].now != ch ) {
  2166.         old = win[no].now;
  2167.         win[no].now = ch;
  2168.         WIN_puts(no,memo_buf);
  2169.         win[no].now = old;
  2170.         } else
  2171.         WIN_puts(no,memo_buf);
  2172.     else if ( memo_ptr != ERR )
  2173.         WIN_ins_ptr(no,ch,memo_ptr);
  2174.     }
  2175. }
  2176.  
  2177. void    MEMO_event(register EVENT *ep)
  2178. {
  2179.     switch(ep->now) {
  2180.     case EVT_CLIP_MOS:
  2181.     EVT_clip_on(ep);
  2182.     case EVT_ON_MOS:
  2183.     DSP_mos(1);
  2184.     break;
  2185.  
  2186.     case EVT_SELECT_MOS:
  2187.     EVT_clip_off(ep);
  2188.     DSP_mos(0);
  2189.     MSG_wind("memo_up");
  2190.     break;
  2191.  
  2192.     case EVT_DOLACK_MOS:
  2193.     ep->now = EVT_NON;
  2194.     case EVT_MOVE_MOS:
  2195.     EVT_clip_off(ep);
  2196.     case EVT_OFF_MOS:
  2197.     DSP_mos(0);
  2198.     break;
  2199.     }
  2200. }
  2201.  
  2202. void    MEMO_chk(void)
  2203. {
  2204.     static int memo_flg=FALSE;
  2205.  
  2206.     if ( memo_buf == NULL && memo_ptr == ERR && memo_flg != FALSE ) {
  2207.     EVT_level_free(290);
  2208.     memo_flg = FALSE;
  2209.     DSP_xline(MEMO_X,2,MEMO_X+36,13,COL_WHIS,0);
  2210.  
  2211.     } else if ( (memo_buf != NULL || memo_ptr != ERR) && memo_flg == FALSE ) {
  2212.     EVT_sw(MEMO_X,2,"MEMO",COL_DIA,COL_WHIS,290,MEMO_event,0);
  2213.     memo_flg = TRUE;
  2214.     }
  2215. }
  2216. void    MEMO_word_cut(int no,int pos,int x,int len)
  2217. {
  2218.     int     n;
  2219.     LIN_PTR *lp;
  2220.     char    *p,*s;
  2221.     char    tmp[82];
  2222.  
  2223.     if ( (n = get_lin_pos(no,pos)) != ERR ) {
  2224.     lp = get_lin(n);
  2225.     x = kan_pos(lp->lin,x);
  2226.     p = &(lp->lin[x]);
  2227.     s = tmp;
  2228.     while ( len > 0 ) {
  2229.         if ( iskan(p) ) {
  2230.         *(s++) = *(p++);
  2231.         *(s++) = *(p++);
  2232.         len -= 2;
  2233.         } else if ( *p == '\0' || *p == '\n' ) {
  2234.         *(s++) = ' ';
  2235.         len--;
  2236.         } else {
  2237.         *(s++) = *(p++);
  2238.         len--;
  2239.         }
  2240.     }
  2241.     *s = '\0';
  2242.     } else {
  2243.     memset(tmp,' ',len);
  2244.         tmp[len] = '\0';
  2245.     }
  2246.  
  2247.     if ( memo_buf != NULL )
  2248.     free(memo_buf);
  2249.     memo_buf = strdup(tmp);
  2250.  
  2251.     MEMO_chk();
  2252. }
  2253. void    MEMO_lin_set(int sptr,int eptr)
  2254. {
  2255.     int     i,n,old;
  2256.     LIN_PTR *lp,*tp;
  2257.  
  2258.     if ( memo_buf != NULL )
  2259.     free(memo_buf);
  2260.     memo_buf = NULL;
  2261.  
  2262.     while ( memo_ptr != ERR ) {
  2263.     lp = get_lin(memo_ptr);
  2264.     n = lp->left;
  2265.     xfree(memo_ptr);
  2266.     memo_ptr = n;
  2267.     }
  2268.  
  2269.     n = sptr;
  2270.     tp = NULL;
  2271.     old = ERR;
  2272.     while ( n != ERR && n != eptr ) {
  2273.     i = xalloc();
  2274.     if ( tp != NULL )
  2275.         tp->left = i;
  2276.     else
  2277.         memo_ptr = i;
  2278.  
  2279.     tp = get_lin(i);
  2280.     tp->right = old;
  2281.     old = i;
  2282.  
  2283.     lp = get_lin(n);
  2284.     strcpy(tp->lin,lp->lin);
  2285.     n = lp->left;
  2286.     }
  2287. }
  2288. void    MEMO_line_cut(int no,int pos,int len)
  2289. {
  2290.     int     i,n,old;
  2291.     LIN_PTR *lp,*tp;
  2292.  
  2293.     if ( memo_buf != NULL )
  2294.     free(memo_buf);
  2295.     memo_buf = NULL;
  2296.  
  2297.     while ( memo_ptr != ERR ) {
  2298.     lp = get_lin(memo_ptr);
  2299.     n = lp->left;
  2300.     xfree(memo_ptr);
  2301.     memo_ptr = n;
  2302.     }
  2303.  
  2304.     n = get_lin_pos(no,pos);
  2305.     tp = NULL;
  2306.     old = ERR;
  2307.     while ( n != ERR && pos <= len ) {
  2308.     i = xalloc();
  2309.     if ( tp != NULL )
  2310.         tp->left = i;
  2311.     else
  2312.         memo_ptr = i;
  2313.  
  2314.     tp = get_lin(i);
  2315.     tp->right = old;
  2316.     old = i;
  2317.  
  2318.     lp = get_lin(n);
  2319.     strcpy(tp->lin,lp->lin);
  2320.     n = lp->left;
  2321.     pos++;
  2322.     }
  2323.  
  2324.     MEMO_chk();
  2325. }
  2326. void    WIN_move_cur(int no,int x,int y)
  2327. {
  2328.     WIND    *wp;
  2329.     CHI_PTR *cp;
  2330.     LIN_PTR *lp;
  2331.  
  2332.     wp = &(win[no]);
  2333.     cp = &(wp->child[wp->now]);
  2334.  
  2335.     cp->cur_x = x;
  2336.  
  2337.     if (  y < cp->cur_y )
  2338.     WIN_up_scrool(no,cp->cur_y - y);
  2339.  
  2340.     while ( y > cp->cur_y ) {
  2341.     if ( cp->now_ptr == ERR )
  2342.         WIN_ins_line(no);
  2343.     lp = get_lin(cp->now_ptr);
  2344.     if ( lp->left == ERR )
  2345.         WIN_ins_line(no);
  2346.     WIN_down_scrool(no,1);
  2347.     }
  2348. }
  2349. void    WIN_scrn_event(register EVENT *ep,int x,int y,int sw)
  2350. {
  2351.     WIND    *wp;
  2352.     CHI_PTR *cp;
  2353.     LIN_PTR *lp;
  2354.     int     i,n,xx,yy;
  2355.     static int mode,hit_x,hit_y;
  2356.     static int old_x,old_y,old_sw,old_len,old_cur_y;
  2357.     static int dsp_x1=0,dsp_y1=0,dsp_x2=0,dsp_y2=0;
  2358.     static int pos,len,old_ptr,old_pos,rep_cnt=0,rep_tick=0;
  2359.  
  2360.     wp = &(win[ep->no]);
  2361.     cp = &(wp->child[wp->now]);
  2362.  
  2363.     switch(ep->now) {
  2364.     case EVT_CLIP_MOS:
  2365.     DSP_mos(1);
  2366.     ep->now = EVT_DOLACK_MOS;
  2367.     mode = 0;
  2368.     hit_x = x;
  2369.     hit_y = y;
  2370.     old_x = x / 8;
  2371.     old_y = (y - wp->wind_y - 16) / 16;
  2372.     old_sw = sw;
  2373.     old_len = ERR;
  2374.     pos = cp->lin_pos - cp->cur_y + old_y;
  2375.     old_ptr = cp->now_ptr;
  2376.     old_pos = cp->lin_pos;
  2377.     old_cur_y = cp->cur_y;
  2378.     dsp_x1 = ERR;
  2379.     rep_cnt = 1;
  2380.     rep_tick = 0;
  2381.     break;
  2382.  
  2383.     case EVT_DOLACK_MOS:
  2384.     old_sw = sw;
  2385.     xx = x / 8;
  2386.     yy = (y - wp->wind_y - 16) / 16;
  2387.     switch(mode) {
  2388.     case 0: 
  2389.         if ( old_y >= wp->max_y )
  2390.         break;
  2391.         if ( y >= (hit_y + 8) || y <= (hit_y - 8) )
  2392.         mode = 2;
  2393.         else if ( x >= (hit_x + 8) || x <= (hit_x - 8) )
  2394.         mode = 1;
  2395.         break;
  2396.  
  2397.     case 1:
  2398.         yy = old_y * 16 + wp->wind_y + 16;
  2399.  
  2400.         if ( y < yy )
  2401.         MOS_setpos(x,yy);
  2402.         else if ( y > (yy+15) )
  2403.         MOS_setpos(x,yy+15);
  2404.  
  2405.         len = xx;
  2406.  
  2407.         if ( old_len == len )
  2408.         break;
  2409.  
  2410.         old_len = len;
  2411.  
  2412.         MOS_disp(FALSE);
  2413.         if ( dsp_x1 != ERR )
  2414.         DSP_xline(dsp_x1,dsp_y1,dsp_x2,dsp_y2,7,4);
  2415.  
  2416.         dsp_x1 = old_x * 8 + (len >= old_x ? 0:7);
  2417.         dsp_x2 = len * 8 + (len >= old_x ? 7:0);
  2418.         dsp_y1 = yy;
  2419.         dsp_y2 = yy + 15;
  2420.  
  2421.         DSP_xline(dsp_x1,dsp_y1,dsp_x2,dsp_y2,7,4);
  2422.         MOS_disp(TRUE);
  2423.         break;
  2424.  
  2425.     case 2:
  2426.         cur_dsp_flg = TRUE;
  2427.         if ( y <= (wp->wind_y + 16) ) {
  2428.         if ( ++rep_tick > 20 ) {
  2429.              rep_cnt++;
  2430.              rep_tick = 0;
  2431.         }
  2432.         i = wp->wind_y + 16;
  2433.         if ( y < i )
  2434.             MOS_setpos(x,i);
  2435.         y = i;
  2436.         if ( cp->now_ptr != ERR ) {
  2437.             lp = get_lin(cp->now_ptr);
  2438.             for ( n = rep_cnt ; n > 0 && lp->right != ERR ; n-- ) {
  2439.             cp->now_ptr = lp->right;
  2440.             cp->lin_pos--;
  2441.             if ( --cp->cur_y <= 0 )
  2442.                 cp->cur_y = 0;
  2443.             lp = get_lin(cp->now_ptr);
  2444.             }
  2445.         }
  2446.  
  2447.         } else if ( y >= (wp->wind_y + wp->size_y) ) {
  2448.         if ( ++rep_tick > 20 ) {
  2449.              rep_cnt++;
  2450.              rep_tick = 0;
  2451.         }
  2452.         i = wp->wind_y + wp->size_y;
  2453.         if ( y > i )
  2454.             MOS_setpos(x,i);
  2455.         y = i;
  2456.         if ( cp->now_ptr != ERR ) {
  2457.             lp = get_lin(cp->now_ptr);
  2458.             for ( n = rep_cnt ; n > 0 && lp->left != ERR ; n-- ) {
  2459.             cp->now_ptr = lp->left;
  2460.             cp->lin_pos++;
  2461.             if ( ++cp->cur_y >= wp->max_y )
  2462.                 cp->cur_y = wp->max_y - 1;
  2463.             lp = get_lin(cp->now_ptr);
  2464.             }
  2465.         }
  2466.         } else {
  2467.         rep_tick = 0;
  2468.         rep_cnt = 1;
  2469.         }
  2470.  
  2471.         yy = (y - wp->wind_y - 16) / 16;
  2472.         len = cp->lin_pos - cp->cur_y + yy;
  2473.         if ( old_len == len )
  2474.         break;
  2475.         old_len = len;
  2476.  
  2477.         if ( pos > len ) {
  2478.         i = len;
  2479.         n = pos;
  2480.         } else {
  2481.         i = pos;
  2482.         n = len;
  2483.         }
  2484.         MOS_disp(FALSE);
  2485.         WIN_col_buf(ep->no,i,n);
  2486.         MOS_disp(TRUE);
  2487.         break;
  2488.     }
  2489.     break;
  2490.  
  2491.     case EVT_DLSEL_MOS:
  2492.     DSP_mos(0);
  2493.     switch(mode) {
  2494.     case 0:
  2495.         if ( act_wind != ep->no )
  2496.         WIN_act_cheng(ep->no);
  2497.  
  2498.         if ( (old_sw & 2) != 0 ) {
  2499.         if ( cp->cur_x == old_x && cp->cur_y == old_y )
  2500.             MEMO_insrt(ep->no,wp->now);
  2501.         else if ( ep->no != TERM )
  2502.             WIN_move_cur(ep->no,old_x,old_y);
  2503.         }
  2504.         break;
  2505.  
  2506.     case 1:
  2507.         if ( dsp_x1 != ERR ) {
  2508.             MOS_disp(FALSE);
  2509.         DSP_xline(dsp_x1,dsp_y1,dsp_x2,dsp_y2,7,4);
  2510.             MOS_disp(TRUE);
  2511.         }
  2512.         if ( len >= old_x )
  2513.         len = len - old_x + 1;
  2514.         else {
  2515.         i = old_x - len;
  2516.         old_x = len;
  2517.         len = i;
  2518.         }
  2519.         MEMO_word_cut(ep->no,pos,old_x,len);
  2520.         break;
  2521.  
  2522.     case 2:
  2523.         cur_dsp_flg = FALSE;
  2524.         cp->now_ptr = old_ptr;
  2525.         cp->lin_pos = old_pos;
  2526.         cp->cur_y = old_cur_y;
  2527.         MOS_disp(FALSE);
  2528.         WIN_dsp_buf(ep->no);
  2529.         MOS_disp(TRUE);
  2530.         if ( pos > len ) {
  2531.         i = pos;
  2532.         pos = len;
  2533.         len = i;
  2534.         }
  2535.         MEMO_line_cut(ep->no,pos,len);
  2536.         break;
  2537.     }
  2538.     break;
  2539.     }
  2540. }
  2541.  
  2542. void    WIN_event(register EVENT *ep)
  2543. {
  2544.     int     i;
  2545.     static int tik=0;
  2546.     static int cnt=1;
  2547.  
  2548.     switch(ep->now) {
  2549.     case EVT_CLIP_MOS:
  2550.     EVT_clip_on(ep);
  2551.     if ( ep->no == 1 || ep->no == 2 ) {
  2552.         ep->now = EVT_REP_MOS;
  2553.         tik = 0;
  2554.         cnt = 1;
  2555.         break;
  2556.     }
  2557.  
  2558.     case EVT_ON_MOS:
  2559.     DSP_mos(1);
  2560.     break;
  2561.  
  2562.     case EVT_SELECT_MOS:
  2563.     EVT_clip_off(ep);
  2564.     DSP_mos(0);
  2565.     if ( ep->no == 0 && act_wind != (ep->level - 200) )
  2566.         WIN_act_cheng(ep->level-200);
  2567.     break;
  2568.  
  2569.     case EVT_REP_MOS:
  2570.     if ( ++tik >= 50 ) {
  2571.         tik = 0;
  2572.         cnt++;
  2573.     }
  2574.  
  2575.     if ( ep->no == 1 )
  2576.         i = WIN_down_scrool(ep->level - 200,cnt);
  2577.     else
  2578.         i = WIN_up_scrool(ep->level - 200,cnt);
  2579.  
  2580.     if ( i != ERR ) {
  2581.         MOS_disp(FALSE);
  2582.         WIN_dsp_buf(ep->level - 200);
  2583.         MOS_disp(TRUE);
  2584.     }
  2585.     break;
  2586.  
  2587.     case EVT_DOLACK_MOS:
  2588.     ep->now = EVT_NON;
  2589.     case EVT_MOVE_MOS:
  2590.     EVT_clip_off(ep);
  2591.     case EVT_OFF_MOS:
  2592.     DSP_mos(0);
  2593.     break;
  2594.     }
  2595. }
  2596.  
  2597. void    WIN_cmd_event(register EVENT *ep)
  2598. {
  2599.     WIND    *wp;
  2600.     CHI_PTR *cp;
  2601.  
  2602.     switch(ep->now) {
  2603.     case EVT_CLIP_MOS:
  2604.     EVT_clip_on(ep);
  2605.     case EVT_ON_MOS:
  2606.     DSP_mos(1);
  2607.     break;
  2608.  
  2609.     case EVT_SELECT_MOS:
  2610.     EVT_clip_off(ep);
  2611.     DSP_mos(0);
  2612.     switch(ep->no) {
  2613.     case 0:
  2614.         if ( ep->level == (200 + TERM) ) {
  2615.         TERM_pause_abort();
  2616.         } else {
  2617.         macvalset("WIND",ep->level - 200);
  2618.         MSG_wind("wind_upload");
  2619.         }
  2620.         break;
  2621.     case 1:
  2622.         macvalset("WIND",ep->level - 200);
  2623.         MSG_wind("wind_menu");
  2624.         break;
  2625.     case 2:
  2626.         MSG_wind("login");
  2627.         break;
  2628.     case 3:
  2629.         MSG_wind("down_load");
  2630.         break;
  2631.     case 4:
  2632.         macvalset("WIND",ep->level - 200);
  2633.         MSG_wind("wind_secret");
  2634.         wp = &(win[ep->level-200]);
  2635.         cp = &(wp->child[wp->now]);
  2636.         cp->sec_flg = (cp->sec_flg == FALSE ? TRUE:FALSE);
  2637.         MOS_disp(FALSE);
  2638.         WIN_dsp_secret(ep->level-200,cp->sec_flg);
  2639.         MOS_disp(TRUE);
  2640.         break;
  2641.     }
  2642.     break;
  2643.  
  2644.     case EVT_DOLACK_MOS:
  2645.     ep->now = EVT_NON;
  2646.     case EVT_MOVE_MOS:
  2647.     EVT_clip_off(ep);
  2648.     case EVT_OFF_MOS:
  2649.     DSP_mos(0);
  2650.     break;
  2651.     }
  2652. }
  2653. void    CHILD_set(int no,int ch)
  2654. {
  2655.     WIND    *wp;
  2656.     CHI_PTR *cp;
  2657.  
  2658.     if ( no >= MAX_WIND || no < 0 )
  2659.     no = act_wind;
  2660.     if ( ch >= CHILD_MAX || ch < 0 )
  2661.     ch = win[no].now;
  2662.  
  2663.     wp = &(win[no]);
  2664.     if ( ch == wp->now )
  2665.     return;
  2666.     wp->now = ch;
  2667.     cp = &(wp->child[ch]);
  2668.     WIN_child_dsp(no);
  2669.     WIN_dsp_pause(no,cp->pas_flg);
  2670.     WIN_dsp_secret(no,cp->sec_flg);
  2671.     WIN_dsp_buf(no);
  2672. }
  2673. void    WIN_child_event(register EVENT *ep)
  2674. {
  2675.     WIND    *wp;
  2676.     CHI_PTR *cp;
  2677.  
  2678.     switch(ep->now) {
  2679.     case EVT_CLIP_MOS:
  2680.     EVT_clip_on(ep);
  2681.     case EVT_ON_MOS:
  2682.     DSP_mos(1);
  2683.     break;
  2684.  
  2685.     case EVT_SELECT_MOS:
  2686.     EVT_clip_off(ep);
  2687.     DSP_mos(0);
  2688.     wp = &win[ep->level-200];
  2689.     if ( wp->now == ep->no )
  2690.         break;
  2691.  
  2692.     macvalset("WIND",ep->level - 200);
  2693.     macvalset("OCH",wp->now);
  2694.     macvalset("CH",ep->no);
  2695.     MSG_wind("wind_child");
  2696.     break;
  2697.  
  2698.     case EVT_DOLACK_MOS:
  2699.     ep->now = EVT_NON;
  2700.     case EVT_MOVE_MOS:
  2701.     EVT_clip_off(ep);
  2702.     case EVT_OFF_MOS:
  2703.     DSP_mos(0);
  2704.     break;
  2705.     }
  2706. }
  2707.  
  2708. void    WIN_redisp(int no)
  2709. {
  2710.     int     i,n,c;
  2711.     register WIND *wp;
  2712.  
  2713.     wp = &win[no];
  2714.     DSP_box(0,wp->wind_y,639,wp->wind_y+15,COL_LINE,wp->color);
  2715.  
  2716.     EVT_level_free(200+no);
  2717.     EVT_sw(W_NAME_X,wp->wind_y+2,win_name[no],
  2718.         no == act_wind ? COL_RED:COL_CHR,wp->color,
  2719.         200+no,WIN_event,0);
  2720.  
  2721.     EVT_sw(W_UPLOAD_X,wp->wind_y+2,
  2722.         no == TERM ? "PAUSE":"UPLOAD",
  2723.         wind_col2[no],wp->color,200+no,WIN_cmd_event,0);
  2724.  
  2725.     EVT_sw(W_MENU_X,wp->wind_y+2,"MENU",wind_col2[no],wp->color,
  2726.         200+no,WIN_cmd_event,1);
  2727.  
  2728.     if ( no == TERM ) {
  2729.     EVT_sw(W_DIAL_X,wp->wind_y+2,"DIAL",wind_col2[no],wp->color,
  2730.         200+no,WIN_cmd_event,2);
  2731.     EVT_sw(W_DOWNLD_X,wp->wind_y+2,"DOWN",wind_col2[no],wp->color,
  2732.         200+no,WIN_cmd_event,3);
  2733.     }
  2734.  
  2735.     EVT_sw(W_SECRET_X,wp->wind_y+2,"SECRET",
  2736.         wind_col2[no],wp->color,200+no,WIN_cmd_event,4);
  2737.  
  2738.     for ( i = 0 ; i < CHILD_MAX ; i++ ) {
  2739.     EVT_sw(W_CHILD_X+i*24,wp->wind_y+2,"  ",wind_col2[no],wp->color,
  2740.         200+no,WIN_child_event,i);
  2741.     }
  2742.     WIN_child_dsp(no);
  2743.  
  2744.     EVT_sw(W_UP_X,wp->wind_y+2,"△",wind_col2[no],wp->color,
  2745.         200+no,WIN_event,2);
  2746.     EVT_sw(W_DOWN_X,wp->wind_y+2,"▽",wind_col2[no],wp->color,
  2747.         200+no,WIN_event,1);
  2748.  
  2749.     EVT_sw(W_MOVE_X,wp->wind_y+2,"∧∨",wind_col2[no],wp->color,
  2750.         200+no,WIN_move_event,no);
  2751.  
  2752.     EVT_set_node(0,wp->wind_y+16,639,wp->wind_y+wp->size_y-1,
  2753.         200+no,WIN_scrn_event,no);
  2754.  
  2755.     WIN_act_man(no);
  2756.     WIN_dsp_buf(no);
  2757.     WIN_dsp_pause(no,win[no].child[win[no].now].pas_flg);
  2758.     WIN_dsp_secret(no,win[no].child[win[no].now].sec_flg);
  2759.  
  2760.     if ( no == TERM && lin_flg != FALSE )
  2761.     LIN_buf_dsp();
  2762.  
  2763.     if ( no == TERM ) {
  2764.     WIN_dsp_down(down_fp != NULL ? TRUE:FALSE);
  2765.         if ( (log_max = macval("_LOGMAX")) <= 0 )
  2766.         log_max = 1000;
  2767.  
  2768.     } else if ( scl_flg != FALSE ) {
  2769.     for ( i = 0 ; i < 80 ; i++ ) {
  2770.         n = i * 8 + 4;
  2771.         c = ((i+1) % 10) == 0 ? COL_RED:
  2772.         (((i+1) % 5) == 0 ? COL_DIA:COL_CHR);
  2773.         DSP_line(n,wp->wind_y+15,n,wp->wind_y+15,c,0);
  2774.     }
  2775.     }
  2776. }
  2777.  
  2778. void    WIN_resize(void)
  2779. {
  2780.     int     i,n;
  2781.     register WIND    *wp;
  2782.  
  2783.     MOS_disp(FALSE);
  2784.     DSP_xline(0,16,639,463,0,0);
  2785.     cur_wind = ERR;
  2786.     cur_dsp_ptn = macval("_CUR_PTN") * 2;
  2787.     if ( (cur_dsp_col = macval("_CUR_COL")) == 0 )
  2788.     cur_dsp_col = 15;
  2789.  
  2790.     for ( n = i = 0 ; i < MAX_WIND ; i++ ) {
  2791.     wp = &win[i];
  2792.     if ( wp->open_flg != FALSE ) {
  2793.         wp->wind_y = win_tbl[wind_count].w[n].top;
  2794.         wp->size_y = win_tbl[wind_count].w[n].siz;
  2795.         if ( i == TERM && lin_flg != FALSE )
  2796.             wp->max_y = (wp->size_y - 32) / FONT_SIZ;
  2797.         else
  2798.             wp->max_y = (wp->size_y - 16) / FONT_SIZ;
  2799.         WIN_redisp(i);
  2800.         n++;
  2801.     } else {
  2802.         EVT_level_free(200+i);
  2803.         WIN_act_man(i);
  2804.     }
  2805.     }
  2806.     MOS_disp(TRUE);
  2807. }
  2808.  
  2809. void    WIN_open(int no)
  2810. {
  2811.     int     i;
  2812.     register WIND    *wp;
  2813.  
  2814.     wp = &win[no];
  2815.  
  2816.     if ( wind_count == 1 && wp->open_flg != FALSE )
  2817.     return;
  2818.  
  2819.     wp->open_flg = (wp->open_flg != FALSE ? FALSE:TRUE);
  2820.  
  2821.     macset("MODE",wp->open_flg != FALSE ? "OPEN":"CLOSE");
  2822.     macvalset("WIND",no);
  2823.     MSG_wind(WIND_MSG);
  2824.  
  2825.     if ( no == act_wind && wp->open_flg == FALSE ) {
  2826.     for ( i = 0 ; i < MAX_WIND ; i++ ) {
  2827.         if ( win[i].open_flg != FALSE ) {
  2828.         act_wind = i;
  2829.         macvalset("ACTWIND",act_wind);
  2830.         break;
  2831.         }
  2832.     }
  2833.     }
  2834.  
  2835.     if ( wp->open_flg != FALSE )
  2836.     wind_count++;
  2837.     else
  2838.     wind_count--;
  2839.  
  2840.     WIN_resize();
  2841. }
  2842. void    WIN_init(void)
  2843. {
  2844.     int     i,j,top,siz;
  2845.     register WIND    *wp;
  2846.     register CHI_PTR  *cp;
  2847.  
  2848.     for ( i = 1 ; i <= MAX_WIND ; i++ ) {
  2849.     top = 16;
  2850.     siz = 448 / i;
  2851.     for ( j = 0 ; j < i ; j++ ) {
  2852.         win_tbl[i].w[j].top = top;
  2853.         win_tbl[i].w[j].siz = siz;
  2854.         top += siz;
  2855.     }
  2856.     }
  2857.  
  2858.     for ( i = 0 ; i < MAX_WIND ; i++ ) {
  2859.     wp = &win[i];
  2860.     wp->open_flg = FALSE;
  2861.     wp->ins_mode = (i == 0 ? FALSE:TRUE);
  2862.     wp->wrt_mode = 0;
  2863.     wp->color = wind_col[i];
  2864.     wp->now = 0;
  2865.     for ( j = 0 ; j < CHILD_MAX ; j++ ) {
  2866.         cp = &(wp->child[j]);
  2867.         cp->lin_max = cp->lin_pos = 0;
  2868.         cp->cur_x = cp->cur_y = 0;
  2869.         cp->top_ptr = cp->now_ptr = ERR;
  2870.         cp->bak_cod = '\0';
  2871.         cp->pas_flg = cp->sec_flg = cp->wrt_flg = FALSE;
  2872.         cp->file_name = NULL;
  2873.     }
  2874.     WIN_act_man(i);
  2875.     }
  2876.  
  2877.     WIN_open(TERM);
  2878.     macvalset("ACTWIND",act_wind);
  2879. }
  2880.